mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-10 22:22:48 +02:00
Compare commits
3 commits
ef32fd3482
...
f09e1c075d
Author | SHA1 | Date | |
---|---|---|---|
|
f09e1c075d | ||
|
8eb5f8466f | ||
|
9723753b5c |
2 changed files with 31 additions and 18 deletions
|
@ -430,7 +430,7 @@ async fn handle_left_room(
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
// Left before last sync
|
// Left before last sync
|
||||||
if Some(since) >= left_count {
|
if (Some(since) >= left_count && !include_leave) || Some(next_batch) < left_count {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,21 +79,14 @@ pub(crate) async fn send_transaction_message_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
let txn_start_time = Instant::now();
|
let txn_start_time = Instant::now();
|
||||||
|
let transaction_id = body.transaction_id.to_string();
|
||||||
trace!(
|
trace!(
|
||||||
pdus = body.pdus.len(),
|
pdus = body.pdus.len(),
|
||||||
edus = body.edus.len(),
|
edus = body.edus.len(),
|
||||||
id = ?body.transaction_id,
|
id = transaction_id,
|
||||||
"Processing transaction",
|
"Processing transaction",
|
||||||
);
|
);
|
||||||
|
|
||||||
let pdus = body
|
|
||||||
.pdus
|
|
||||||
.iter()
|
|
||||||
.stream()
|
|
||||||
.broad_then(|pdu| services.rooms.event_handler.parse_incoming_pdu(pdu))
|
|
||||||
.inspect_err(|e| debug_warn!("Could not parse PDU: {e}"))
|
|
||||||
.ready_filter_map(Result::ok);
|
|
||||||
|
|
||||||
let edus = body
|
let edus = body
|
||||||
.edus
|
.edus
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -102,21 +95,29 @@ pub(crate) async fn send_transaction_message_route(
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.stream();
|
.stream();
|
||||||
|
|
||||||
|
let pdus = body
|
||||||
|
.pdus
|
||||||
|
.iter()
|
||||||
|
.stream()
|
||||||
|
.broad_then(|pdu| services.rooms.event_handler.parse_incoming_pdu(pdu))
|
||||||
|
.inspect_err(|e| debug_warn!("Could not parse PDU: {e}"))
|
||||||
|
.ready_filter_map(Result::ok);
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
pdus = body.pdus.len(),
|
pdus = body.pdus.len(),
|
||||||
edus = body.edus.len(),
|
edus = body.edus.len(),
|
||||||
elapsed = ?txn_start_time.elapsed(),
|
elapsed = ?txn_start_time.elapsed(),
|
||||||
id = ?body.transaction_id,
|
id = transaction_id,
|
||||||
"Validated transaction",
|
"Validated transaction",
|
||||||
);
|
);
|
||||||
|
|
||||||
let results = handle(&services, &client, body.origin(), txn_start_time, pdus, edus).await?;
|
let results = handle(&services, &client, body.origin(), txn_start_time, pdus, edus, &*transaction_id).await?;
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
pdus = body.pdus.len(),
|
pdus = body.pdus.len(),
|
||||||
edus = body.edus.len(),
|
edus = body.edus.len(),
|
||||||
elapsed = ?txn_start_time.elapsed(),
|
elapsed = ?txn_start_time.elapsed(),
|
||||||
id = ?body.transaction_id,
|
id = transaction_id,
|
||||||
"Finished txn",
|
"Finished txn",
|
||||||
);
|
);
|
||||||
for (id, result) in &results {
|
for (id, result) in &results {
|
||||||
|
@ -142,11 +143,13 @@ async fn handle(
|
||||||
started: Instant,
|
started: Instant,
|
||||||
pdus: impl Stream<Item = Pdu> + Send,
|
pdus: impl Stream<Item = Pdu> + Send,
|
||||||
edus: impl Stream<Item = Edu> + Send,
|
edus: impl Stream<Item = Edu> + Send,
|
||||||
|
transaction_id: &str,
|
||||||
) -> Result<ResolvedMap> {
|
) -> Result<ResolvedMap> {
|
||||||
|
let handle_start = Instant::now();
|
||||||
edus.for_each_concurrent(automatic_width(), |edu| handle_edu(services, client, origin, edu))
|
edus.for_each_concurrent(automatic_width(), |edu| handle_edu(services, client, origin, edu))
|
||||||
.boxed()
|
.boxed()
|
||||||
.await;
|
.await;
|
||||||
|
let pdu_start = Instant::now();
|
||||||
// group pdus by room
|
// group pdus by room
|
||||||
let pdus = pdus
|
let pdus = pdus
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -157,14 +160,14 @@ async fn handle(
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
let results_start = Instant::now();
|
||||||
// we can evaluate rooms concurrently
|
// we can evaluate rooms concurrently
|
||||||
let results: ResolvedMap = pdus
|
let results: ResolvedMap = pdus
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_stream()
|
.try_stream()
|
||||||
.broad_and_then(|(room_id, pdus): (_, Vec<_>)| {
|
.broad_and_then(|(room_id, pdus): (_, Vec<_>)| {
|
||||||
let count = pdus.len();
|
let count = pdus.len();
|
||||||
handle_room(services, client, origin, started, room_id, pdus.into_iter(), count)
|
handle_room(services, client, origin, started, room_id, pdus.into_iter(), count, transaction_id)
|
||||||
.map_ok(Vec::into_iter)
|
.map_ok(Vec::into_iter)
|
||||||
.map_ok(IterStream::try_stream)
|
.map_ok(IterStream::try_stream)
|
||||||
})
|
})
|
||||||
|
@ -172,7 +175,14 @@ async fn handle(
|
||||||
.try_collect()
|
.try_collect()
|
||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
let handle_stop = Instant::now();
|
||||||
|
info!(
|
||||||
|
edus = pdu_start.saturating_duration_since(handle_start).as_micros(),
|
||||||
|
pdus = results_start.saturating_duration_since(pdu_start).as_micros(),
|
||||||
|
handle_room = handle_stop.saturating_duration_since(results_start).as_micros(),
|
||||||
|
transaction_id = ?transaction_id,
|
||||||
|
"handled incoming transaction",
|
||||||
|
);
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +194,7 @@ async fn handle_room(
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
pdus: impl Iterator<Item = Pdu> + Send,
|
pdus: impl Iterator<Item = Pdu> + Send,
|
||||||
count: usize,
|
count: usize,
|
||||||
|
transaction_id: &str,
|
||||||
) -> Result<Vec<(OwnedEventId, Result)>> {
|
) -> Result<Vec<(OwnedEventId, Result)>> {
|
||||||
let _room_lock = services
|
let _room_lock = services
|
||||||
.rooms
|
.rooms
|
||||||
|
@ -201,6 +212,7 @@ async fn handle_room(
|
||||||
trace!(
|
trace!(
|
||||||
%room_id,
|
%room_id,
|
||||||
%event_id,
|
%event_id,
|
||||||
|
transaction_id = ?transaction_id,
|
||||||
pdu = n + 1,
|
pdu = n + 1,
|
||||||
total = count,
|
total = count,
|
||||||
pdu_elapsed = ?pdu_start_time.elapsed(),
|
pdu_elapsed = ?pdu_start_time.elapsed(),
|
||||||
|
@ -217,11 +229,12 @@ async fn handle_room(
|
||||||
info!(
|
info!(
|
||||||
%room_id,
|
%room_id,
|
||||||
%event_id,
|
%event_id,
|
||||||
|
transaction_id = ?transaction_id,
|
||||||
pdu = n + 1,
|
pdu = n + 1,
|
||||||
total = count,
|
total = count,
|
||||||
pdu_elapsed = ?pdu_start_time.elapsed(),
|
pdu_elapsed = ?pdu_start_time.elapsed(),
|
||||||
txn_elapsed = ?txn_start_time.elapsed(),
|
txn_elapsed = ?txn_start_time.elapsed(),
|
||||||
"Finished handling PDU {event_id}",
|
"Finished handling PDU",
|
||||||
);
|
);
|
||||||
n += 1;
|
n += 1;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue