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:
parent
eb39a90057
commit
b89ca3955a
1 changed files with 162 additions and 19 deletions
|
|
@ -15,6 +15,7 @@ use std::path::Path;
|
|||
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use futures_util::StreamExt as _;
|
||||
use matrix_sdk::ruma::OwnedRoomId;
|
||||
use matrix_sdk::ruma::events::StateEventType;
|
||||
use matrix_sdk::sliding_sync::{SlidingSyncList, SlidingSyncMode, Version};
|
||||
use matrix_sdk::{Client, SqliteCryptoStore};
|
||||
|
|
@ -115,12 +116,13 @@ fn required_state() -> Vec<(StateEventType, String)> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Poll sliding sync for `client`, calling `after_update` once per response.
|
||||
/// Poll sliding sync for `client`, calling `after_update` once per response with
|
||||
/// the rooms that response touched.
|
||||
/// Returns `Err` once 5 polls in a row have failed, so the caller can fall
|
||||
/// back to `/sync`.
|
||||
pub async fn run<F, Fut>(client: &Client, after_update: F) -> Result<()>
|
||||
where
|
||||
F: Fn() -> Fut,
|
||||
F: Fn(Vec<OwnedRoomId>) -> Fut,
|
||||
Fut: Future<Output = ()>,
|
||||
{
|
||||
let list = SlidingSyncList::builder("all-rooms")
|
||||
|
|
@ -143,9 +145,9 @@ where
|
|||
let mut errors = ErrorRun::default();
|
||||
while let Some(update) = stream.next().await {
|
||||
match update {
|
||||
Ok(_) => {
|
||||
Ok(summary) => {
|
||||
errors.ok();
|
||||
after_update().await;
|
||||
after_update(summary.rooms).await;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "sliding sync poll failed");
|
||||
|
|
|
|||
Loading…
Reference in a new issue