@@ -1407,7 +1407,7 @@ mod private {
1407
1407
pub async fn handle_backpagination (
1408
1408
& mut self ,
1409
1409
events : Vec < TimelineEvent > ,
1410
- new_gap : Option < Gap > ,
1410
+ mut new_gap : Option < Gap > ,
1411
1411
prev_gap_id : Option < ChunkIdentifier > ,
1412
1412
sender : & Sender < RoomEventCacheUpdate > ,
1413
1413
) -> Result < BackPaginationOutcome , EventCacheError > {
@@ -1444,17 +1444,16 @@ mod private {
1444
1444
} else {
1445
1445
// All new events are duplicated, they can all be ignored.
1446
1446
events. clear ( ) ;
1447
+ // The gap can be ditched too, as it won't be useful to backpaginate any
1448
+ // further.
1449
+ new_gap = None ;
1447
1450
} ;
1448
1451
1449
1452
self . with_events_mut ( false , |room_events| {
1450
1453
// Reverse the order of the events as `/messages` has been called with `dir=b`
1451
1454
// (backwards). The `RoomEvents` API expects the first event to be the oldest.
1452
1455
// Let's re-order them for this block.
1453
- let reversed_events = events
1454
- . iter ( )
1455
- . rev ( )
1456
- . cloned ( )
1457
- . collect :: < Vec < _ > > ( ) ;
1456
+ let reversed_events = events. iter ( ) . rev ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
1458
1457
1459
1458
let first_event_pos = room_events. events ( ) . next ( ) . map ( |( item_pos, _) | item_pos) ;
1460
1459
@@ -1467,9 +1466,11 @@ mod private {
1467
1466
1468
1467
trace ! ( "replacing previous gap with the back-paginated events" ) ;
1469
1468
1470
- // Replace the gap with the events we just deduplicated. This might get rid of the
1471
- // underlying gap, if the conditions are favorable to us.
1472
- room_events. replace_gap_at ( reversed_events. clone ( ) , gap_id)
1469
+ // Replace the gap with the events we just deduplicated. This might get rid of
1470
+ // the underlying gap, if the conditions are favorable to
1471
+ // us.
1472
+ room_events
1473
+ . replace_gap_at ( reversed_events. clone ( ) , gap_id)
1473
1474
. expect ( "gap_identifier is a valid chunk id we read previously" )
1474
1475
} else if let Some ( pos) = first_event_pos {
1475
1476
// No prior gap, but we had some events: assume we need to prepend events
@@ -1493,20 +1494,17 @@ mod private {
1493
1494
1494
1495
// And insert the new gap if needs be.
1495
1496
//
1496
- // We only do this when at least one new, non-duplicated event, has been added to
1497
- // the chunk. Otherwise it means we've back-paginated all the known events.
1498
- if !all_duplicates {
1499
- if let Some ( new_gap) = new_gap {
1500
- if let Some ( new_pos) = insert_new_gap_pos {
1501
- room_events
1502
- . insert_gap_at ( new_gap, new_pos)
1503
- . expect ( "events_chunk_pos represents a valid chunk position" ) ;
1504
- } else {
1505
- room_events. push_gap ( new_gap) ;
1506
- }
1497
+ // We only do this when at least one new, non-duplicated event, has been added
1498
+ // to the chunk. Otherwise it means we've back-paginated all the
1499
+ // known events.
1500
+ if let Some ( new_gap) = new_gap {
1501
+ if let Some ( new_pos) = insert_new_gap_pos {
1502
+ room_events
1503
+ . insert_gap_at ( new_gap, new_pos)
1504
+ . expect ( "events_chunk_pos represents a valid chunk position" ) ;
1505
+ } else {
1506
+ room_events. push_gap ( new_gap) ;
1507
1507
}
1508
- } else {
1509
- debug ! ( "not storing previous batch token, because we deduplicated all new back-paginated events" ) ;
1510
1508
}
1511
1509
1512
1510
reversed_events
0 commit comments