mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-27 02:45:27 +00:00
limit sync response events to within the since/next_batch window
fixes #606 Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5256cad396
commit
bae0667066
|
@ -9,7 +9,8 @@ pub(crate) use self::{v3::sync_events_route, v4::sync_events_v4_route};
|
|||
use crate::{service::Services, Error, PduEvent, Result};
|
||||
|
||||
async fn load_timeline(
|
||||
services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, limit: usize,
|
||||
services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount,
|
||||
next_batch: Option<PduCount>, limit: usize,
|
||||
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
|
||||
let last_timeline_count = services
|
||||
.rooms
|
||||
|
@ -26,7 +27,8 @@ async fn load_timeline(
|
|||
.timeline
|
||||
.pdus_rev(Some(sender_user), room_id, None)
|
||||
.await?
|
||||
.ready_take_while(|(pducount, _)| *pducount > roomsincecount);
|
||||
.ready_skip_while(|&(pducount, _)| pducount > next_batch.unwrap_or_else(PduCount::max))
|
||||
.ready_take_while(|&(pducount, _)| pducount > roomsincecount);
|
||||
|
||||
// Take the last events for the timeline
|
||||
let timeline_pdus: Vec<_> = non_timeline_pdus
|
||||
|
|
|
@ -540,7 +540,8 @@ async fn load_joined_room(
|
|||
let insert_lock = services.rooms.timeline.mutex_insert.lock(room_id).await;
|
||||
drop(insert_lock);
|
||||
|
||||
let (timeline_pdus, limited) = load_timeline(services, sender_user, room_id, sincecount, 10_usize).await?;
|
||||
let (timeline_pdus, limited) =
|
||||
load_timeline(services, sender_user, room_id, sincecount, Some(next_batchcount), 10_usize).await?;
|
||||
|
||||
let send_notification_counts = !timeline_pdus.is_empty()
|
||||
|| services
|
||||
|
|
|
@ -473,7 +473,7 @@ pub(crate) async fn sync_events_v4_route(
|
|||
(timeline_pdus, limited) = (Vec::new(), true);
|
||||
} else {
|
||||
(timeline_pdus, limited) =
|
||||
match load_timeline(&services, sender_user, room_id, roomsincecount, *timeline_limit).await {
|
||||
match load_timeline(&services, sender_user, room_id, roomsincecount, None, *timeline_limit).await {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
warn!("Encountered missing timeline in {}, error {}", room_id, err);
|
||||
|
|
Loading…
Reference in a new issue