Commit bdc4031c08

bdc4031c0839a008ad1c815889e1c53cab71cd1b

parent: a05dcfd08a

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-31 12:43 UTC
committer: <strk@kbt.io>

fix: keep interactive history pages responsive

Layout: unified · split

src/commands/matrix.rs +1 −1
@@ -323,7 +323,7 @@ Use /matrix [command] help to find out more.\n",
323 } 323 }
324 324
325 Weechat::spawn(async move { 325 Weechat::spawn(async move {
326 let result = room.get_messages().await; 326 let result = room.get_interactive_history_page().await;
327 room.print_history_page_result(result); 327 room.print_history_page_result(result);
328 }) 328 })
329 .detach(); 329 .detach();
src/connection.rs +2 −2
@@ -62,7 +62,6 @@ use crate::{
62 62
63const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); 63const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
64const SSO_CALLBACK_PORT: u16 = 29_325; 64const SSO_CALLBACK_PORT: u16 = 29_325;
65const HISTORY_BATCH_SIZE: u16 = 200;
66 65
67pub struct InteractiveAuthInfo { 66pub struct InteractiveAuthInfo {
68 pub user: String, 67 pub user: String,
@@ -261,6 +260,7 @@ impl Connection {
261 &self, 260 &self,
262 room: Room, 261 room: Room,
263 prev_batch: PrevBatch, 262 prev_batch: PrevBatch,
263 limit: u16,
264 ) -> MatrixResult<Messages> { 264 ) -> MatrixResult<Messages> {
265 self.spawn(async move { 265 self.spawn(async move {
266 let mut request = match &prev_batch { 266 let mut request = match &prev_batch {
@@ -271,7 +271,7 @@ impl Connection {
271 MessagesOptions::forward().from(Some(t.as_ref())) 271 MessagesOptions::forward().from(Some(t.as_ref()))
272 } 272 }
273 }; 273 };
274 request.limit = HISTORY_BATCH_SIZE.into(); 274 request.limit = limit.into();
275 275
276 room.messages(request).await 276 room.messages(request).await
277 }) 277 })
src/room/mod.rs +21 −1
@@ -130,6 +130,8 @@ pub enum HistoryPageResult {
130 130
131const HISTORY_PAGE_TAGS: [&str; 2] = 131const HISTORY_PAGE_TAGS: [&str; 2] =
132 ["matrix_history_page", "matrix_smart_filter"]; 132 ["matrix_history_page", "matrix_smart_filter"];
133const RESTORED_HISTORY_BATCH_SIZE: u16 = 25;
134const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25;
133 135
134fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> { 136fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> {
135 // A restored SDK room does not always have a sync pagination token in its 137 // A restored SDK room does not always have a sync pagination token in its
@@ -1953,6 +1955,16 @@ impl MatrixRoom {
1953 } 1955 }
1954 1956
1955 pub async fn get_messages(&self) -> HistoryPageResult { 1957 pub async fn get_messages(&self) -> HistoryPageResult {
1958 self.get_messages_with_limit(RESTORED_HISTORY_BATCH_SIZE)
1959 .await
1960 }
1961
1962 pub async fn get_interactive_history_page(&self) -> HistoryPageResult {
1963 self.get_messages_with_limit(INTERACTIVE_HISTORY_BATCH_SIZE)
1964 .await
1965 }
1966
1967 async fn get_messages_with_limit(&self, limit: u16) -> HistoryPageResult {
1956 let messages_lock = self.messages_in_flight.clone(); 1968 let messages_lock = self.messages_in_flight.clone();
1957 1969
1958 let connection = self.connection.borrow().as_ref().cloned(); 1970 let connection = self.connection.borrow().as_ref().cloned();
@@ -1977,7 +1989,9 @@ impl MatrixRoom {
1977 let room = self.room(); 1989 let room = self.room();
1978 let room_id = room.room_id().to_owned(); 1990 let room_id = room.room_id().to_owned();
1979 1991
1980 if let Ok(r) = connection.room_messages(room, prev_batch).await { 1992 if let Ok(r) =
1993 connection.room_messages(room, prev_batch, limit).await
1994 {
1981 let added = r.chunk.len(); 1995 let added = r.chunk.len();
1982 let exhausted = r.chunk.is_empty() || r.end.is_none(); 1996 let exhausted = r.chunk.is_empty() || r.end.is_none();
1983 1997
@@ -2470,6 +2484,12 @@ mod tests {
2470 )))); 2484 ))));
2471 } 2485 }
2472 2486
2487 #[test]
2488 fn interactive_history_pages_are_bounded() {
2489 assert_eq!(INTERACTIVE_HISTORY_BATCH_SIZE, 25);
2490 assert_eq!(RESTORED_HISTORY_BATCH_SIZE, 25);
2491 }
2492
2473 #[test] 2493 #[test]
2474 fn history_page_markers_are_machine_readable_and_hideable() { 2494 fn history_page_markers_are_machine_readable_and_hideable() {
2475 assert_eq!( 2495 assert_eq!(