Watch
0
0
Fork
You've already forked hyperhive
0

hive-matrix: the unread sweep after a sync looks at the rooms the sync touched, not at every joined room

Each room the sweep looks at costs a live /messages fetch of up to 50 events, and the sweep ran for every joined room after every sync response, so a busy account fetched thousands of times an hour whatever the sync itself carried. The sweep now covers the rooms the response names (sliding sync's UpdateSummary rooms, classic's joined rooms), with a full pass first and every five minutes.
This commit is contained in:
damocles 2026-11-11 16:53:43 +01:00 • committed by mara
commit b89ca3955a

View file

@ -781,15 +781,24 @@ fn account_sync_loop(client: &Client, tag: Option<String>) -> SyncLoop {
// each sweep (see the sweep fns) so re-invites / new messages re-push.
let invite_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
let unread_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
// Both loops run this after each response.
let sweep = move || {
// When the sweep last covered every room, so the others are only looked
// at again after `timeline::FULL_SWEEP_EVERY` (see `timeline::plan`).
let last_full = Arc::new(tokio::sync::Mutex::new(None::<std::time::Instant>));
// Both loops run this after each response, with the rooms it touched.
let sweep = move |changed: Vec<matrix_sdk::ruma::OwnedRoomId>| {
let client = cb_client.clone();
let invite_notified = invite_notified.clone();
let unread_notified = unread_notified.clone();
let last_full = last_full.clone();
let tag = tag.clone();
async move {
timeline::sweep_invites(&client, &invite_notified, tag.as_deref()).await;
timeline::sweep_unread(&client, &unread_notified, tag.as_deref()).await;
let now = std::time::Instant::now();
let scope = timeline::plan(*last_full.lock().await, now, changed);
if scope == timeline::Scope::All {
*last_full.lock().await = Some(now);
}
timeline::sweep_unread(&client, &unread_notified, tag.as_deref(), scope).await;
}
};
Box::pin(async move {
@ -803,8 +812,8 @@ fn account_sync_loop(client: &Client, tag: Option<String>) -> SyncLoop {
tracing::info!("syncing with classic /sync");
}
sync_client
.sync_with_callback(SyncSettings::default().filter(sync_filter()), |_response| {
let sweep = sweep();
.sync_with_callback(SyncSettings::default().filter(sync_filter()), |response| {
let sweep = sweep(response.rooms.joined.keys().cloned().collect());
async move {
sweep.await;
matrix_sdk::LoopCtrl::Continue