From 0cdf03288ab8fa363c313bd929c8b5183d14ab77 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 4 Jun 2024 00:38:53 -0700 Subject: [PATCH] fix missing next_batch for search The previous code would fail to return next_batch if any of the events in the window were not visible to the user. It would also return an unnecessary next_batch when no more results are available if the total number of results is exactly `skip + limit`. This bug will become much more severe with a full filtering implementation, because we will be more likely to trigger it by filtering out events in a search call. Currently, it is only possible to trigger with rooms that have history visibility set to "invited" or "joined". --- src/api/client_server/search.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index 115b01b9..c9b9cd4e 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -130,11 +130,8 @@ pub(crate) async fn search_events_route( .take(limit) .collect(); - let next_batch = if results.len() < limit { - None - } else { - Some((skip + limit).to_string()) - }; + let more_unloaded_results = searches.iter_mut().any(|s| s.peek().is_some()); + let next_batch = more_unloaded_results.then(|| (skip + limit).to_string()); Ok(Ra(search_events::v3::Response::new(ResultCategories { room_events: ResultRoomEvents {