@@ -35,7 +35,7 @@ use std::{
35
35
use async_stream:: stream;
36
36
use futures_core:: stream:: Stream ;
37
37
pub use matrix_sdk_base:: sliding_sync:: http;
38
- use matrix_sdk_common:: { ring_buffer :: RingBuffer , timer} ;
38
+ use matrix_sdk_common:: timer;
39
39
use ruma:: {
40
40
api:: { client:: error:: ErrorKind , OutgoingRequest } ,
41
41
assign, OwnedEventId , OwnedRoomId , RoomId ,
@@ -112,9 +112,6 @@ pub(super) struct SlidingSyncInner {
112
112
/// `position` being updated, before sending a new request.
113
113
position : Arc < AsyncMutex < SlidingSyncPositionMarkers > > ,
114
114
115
- /// Past position markers.
116
- past_positions : StdRwLock < RingBuffer < SlidingSyncPositionMarkers > > ,
117
-
118
115
/// The lists of this Sliding Sync instance.
119
116
lists : AsyncRwLock < BTreeMap < String , SlidingSyncList > > ,
120
117
@@ -258,23 +255,6 @@ impl SlidingSync {
258
255
) -> Result < UpdateSummary , crate :: Error > {
259
256
let pos = Some ( sliding_sync_response. pos . clone ( ) ) ;
260
257
261
- {
262
- debug ! ( "Update position markers" ) ;
263
-
264
- // Look up for this new `pos` in the past position markers.
265
- let past_positions = self . inner . past_positions . read ( ) . unwrap ( ) ;
266
-
267
- // The `pos` received by the server has already been received in the past!
268
- if past_positions. iter ( ) . any ( |position| position. pos == pos) {
269
- error ! (
270
- ?sliding_sync_response,
271
- "Sliding Sync response has ALREADY been handled by the client in the past"
272
- ) ;
273
-
274
- return Err ( Error :: ResponseAlreadyReceived { pos } . into ( ) ) ;
275
- }
276
- }
277
-
278
258
let must_process_rooms_response = self . must_process_rooms_response ( ) . await ;
279
259
280
260
trace ! ( yes = must_process_rooms_response, "Must process rooms response?" ) ;
@@ -425,10 +405,6 @@ impl SlidingSync {
425
405
// Save the new position markers.
426
406
position. pos = pos;
427
407
428
- // Keep this position markers in memory, in case it pops from the server.
429
- let mut past_positions = self . inner . past_positions . write ( ) . unwrap ( ) ;
430
- past_positions. push ( position. clone ( ) ) ;
431
-
432
408
Ok ( update_summary)
433
409
}
434
410
@@ -734,11 +710,6 @@ impl SlidingSync {
734
710
yield Ok ( updates) ;
735
711
}
736
712
737
- // Here, errors we can safely ignore.
738
- Err ( crate :: Error :: SlidingSync ( Error :: ResponseAlreadyReceived { .. } ) ) => {
739
- continue ;
740
- }
741
-
742
713
// Here, errors we **cannot** ignore, and that must stop the sync loop.
743
714
Err ( error) => {
744
715
if error. client_api_error_kind( ) == Some ( & ErrorKind :: UnknownPos ) {
@@ -774,8 +745,8 @@ impl SlidingSync {
774
745
775
746
/// Expire the current Sliding Sync session.
776
747
///
777
- /// Expiring a Sliding Sync session means: resetting `pos`. It also cleans
778
- /// up the `past_positions`, and resets sticky parameters.
748
+ /// Expiring a Sliding Sync session means: resetting `pos`. It also resets
749
+ /// sticky parameters.
779
750
///
780
751
/// This should only be used when it's clear that this session was about to
781
752
/// expire anyways, and should be used only in very specific cases (e.g.
@@ -796,9 +767,6 @@ impl SlidingSync {
796
767
"couldn't invalidate sliding sync frozen state when expiring session: {err}"
797
768
) ;
798
769
}
799
-
800
- let mut past_positions = self . inner . past_positions . write ( ) . unwrap ( ) ;
801
- past_positions. clear ( ) ;
802
770
}
803
771
804
772
// Force invalidation of all the sticky parameters.
@@ -1471,11 +1439,6 @@ mod tests {
1471
1439
1472
1440
// `pos` has been updated.
1473
1441
assert_eq ! ( sliding_sync. inner. position. lock( ) . await . pos, Some ( "0" . to_owned( ) ) ) ;
1474
-
1475
- // `past_positions` has been updated.
1476
- let past_positions = sliding_sync. inner . past_positions . read ( ) . unwrap ( ) ;
1477
- assert_eq ! ( past_positions. len( ) , 1 ) ;
1478
- assert_eq ! ( past_positions. get( 0 ) . unwrap( ) . pos, Some ( "0" . to_owned( ) ) ) ;
1479
1442
}
1480
1443
1481
1444
// Next request doesn't ask to enable the extension.
@@ -1503,19 +1466,12 @@ mod tests {
1503
1466
1504
1467
// `pos` has been updated.
1505
1468
assert_eq ! ( sliding_sync. inner. position. lock( ) . await . pos, Some ( "1" . to_owned( ) ) ) ;
1506
-
1507
- // `past_positions` has been updated.
1508
- let past_positions = sliding_sync. inner . past_positions . read ( ) . unwrap ( ) ;
1509
- assert_eq ! ( past_positions. len( ) , 2 ) ;
1510
- assert_eq ! ( past_positions. get( 0 ) . unwrap( ) . pos, Some ( "0" . to_owned( ) ) ) ;
1511
- assert_eq ! ( past_positions. get( 1 ) . unwrap( ) . pos, Some ( "1" . to_owned( ) ) ) ;
1512
1469
}
1513
1470
1514
- // Next request isn't successful because it receives an already
1471
+ // Next request is successful despite it receives an already
1515
1472
// received `pos` from the server.
1516
1473
{
1517
- // First response with an already seen `pos`.
1518
- let _mock_guard1 = Mock :: given ( SlidingSyncMatcher )
1474
+ let _mock_guard = Mock :: given ( SlidingSyncMatcher )
1519
1475
. respond_with ( |request : & Request | {
1520
1476
// Repeat the txn_id in the response, if set.
1521
1477
let request: PartialRequest = request. body_json ( ) . unwrap ( ) ;
@@ -1529,37 +1485,16 @@ mod tests {
1529
1485
. mount_as_scoped ( & server)
1530
1486
. await ;
1531
1487
1532
- // Second response with a new `pos`.
1533
- let _mock_guard2 = Mock :: given ( SlidingSyncMatcher )
1534
- . respond_with ( |request : & Request | {
1535
- // Repeat the txn_id in the response, if set.
1536
- let request: PartialRequest = request. body_json ( ) . unwrap ( ) ;
1537
-
1538
- ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
1539
- "txn_id" : request. txn_id,
1540
- "pos" : "2" , // <- new!
1541
- } ) )
1542
- } )
1543
- . mount_as_scoped ( & server)
1544
- . await ;
1545
-
1546
1488
let next = sync. next ( ) . await ;
1547
1489
assert_matches ! ( next, Some ( Ok ( _update_summary) ) ) ;
1548
1490
1549
1491
// `pos` has been updated.
1550
- assert_eq ! ( sliding_sync. inner. position. lock( ) . await . pos, Some ( "2" . to_owned( ) ) ) ;
1551
-
1552
- // `past_positions` has been updated.
1553
- let past_positions = sliding_sync. inner . past_positions . read ( ) . unwrap ( ) ;
1554
- assert_eq ! ( past_positions. len( ) , 3 ) ;
1555
- assert_eq ! ( past_positions. get( 0 ) . unwrap( ) . pos, Some ( "0" . to_owned( ) ) ) ;
1556
- assert_eq ! ( past_positions. get( 1 ) . unwrap( ) . pos, Some ( "1" . to_owned( ) ) ) ;
1557
- assert_eq ! ( past_positions. get( 2 ) . unwrap( ) . pos, Some ( "2" . to_owned( ) ) ) ;
1492
+ assert_eq ! ( sliding_sync. inner. position. lock( ) . await . pos, Some ( "0" . to_owned( ) ) ) ;
1558
1493
}
1559
1494
1560
1495
// Stop responding with successful requests!
1561
1496
//
1562
- // When responding with M_UNKNOWN_POS, that regenerates the sticky parameters,
1497
+ // When responding with ` M_UNKNOWN_POS` , that regenerates the sticky parameters,
1563
1498
// so they're reset. It also resets the `pos`.
1564
1499
{
1565
1500
let _mock_guard = Mock :: given ( SlidingSyncMatcher )
@@ -1578,9 +1513,6 @@ mod tests {
1578
1513
// `pos` has been reset.
1579
1514
assert ! ( sliding_sync. inner. position. lock( ) . await . pos. is_none( ) ) ;
1580
1515
1581
- // `past_positions` has been reset.
1582
- assert ! ( sliding_sync. inner. past_positions. read( ) . unwrap( ) . is_empty( ) ) ;
1583
-
1584
1516
// Next request asks to enable the extension again.
1585
1517
let ( request, _, _) =
1586
1518
sliding_sync. generate_sync_request ( & mut LazyTransactionId :: new ( ) ) . await ?;
0 commit comments