@@ -91,17 +91,12 @@ impl Deduplicator {
9191 } ) ;
9292 }
9393
94- let mut outcome = match self {
94+ match self {
9595 Deduplicator :: InMemory ( dedup) => Ok ( dedup. filter_duplicate_events ( events, room_events) ) ,
9696 Deduplicator :: PersistentStore ( dedup) => {
9797 dedup. filter_duplicate_events ( events, room_events) . await
9898 }
99- } ?;
100-
101- sort_events_by_position_descending ( & mut outcome. in_memory_duplicated_event_ids ) ;
102- sort_events_by_position_descending ( & mut outcome. in_store_duplicated_event_ids ) ;
103-
104- Ok ( outcome)
99+ }
105100 }
106101}
107102
@@ -329,23 +324,6 @@ pub(super) struct DeduplicationOutcome {
329324 pub in_store_duplicated_event_ids : Vec < ( OwnedEventId , Position ) > ,
330325}
331326
332- /// Sort events so that they can be removed safely without messing their
333- /// position.
334- ///
335- /// This function sort events by their position if any.
336- ///
337- /// Events must be sorted by their position index, from greatest to lowest, so
338- /// that all positions remain valid inside the same chunk while they are being
339- /// removed. For the sake of debugability, we also sort by position chunk
340- /// identifier, but this is not required.
341- fn sort_events_by_position_descending ( event_ids : & mut [ ( OwnedEventId , Position ) ] ) {
342- event_ids. sort_by ( |( _, a) , ( _, b) | {
343- b. chunk_identifier ( )
344- . cmp ( & a. chunk_identifier ( ) )
345- . then_with ( || a. index ( ) . cmp ( & b. index ( ) ) . reverse ( ) )
346- } ) ;
347- }
348-
349327#[ cfg( test) ]
350328mod tests {
351329 use assert_matches2:: { assert_let, assert_matches} ;
@@ -363,36 +341,6 @@ mod tests {
363341 . into_event ( )
364342 }
365343
366- #[ test]
367- fn test_sort_events_by_position_descending ( ) {
368- let ev1 = owned_event_id ! ( "$ev1" ) ;
369- let ev2 = owned_event_id ! ( "$ev2" ) ;
370- let ev3 = owned_event_id ! ( "$ev3" ) ;
371- let ev4 = owned_event_id ! ( "$ev4" ) ;
372- let ev5 = owned_event_id ! ( "$ev5" ) ;
373-
374- let mut event_ids = vec ! [
375- ( ev1. clone( ) , Position :: new( ChunkIdentifier :: new( 2 ) , 1 ) ) ,
376- ( ev2. clone( ) , Position :: new( ChunkIdentifier :: new( 1 ) , 0 ) ) ,
377- ( ev3. clone( ) , Position :: new( ChunkIdentifier :: new( 2 ) , 0 ) ) ,
378- ( ev4. clone( ) , Position :: new( ChunkIdentifier :: new( 1 ) , 1 ) ) ,
379- ( ev5. clone( ) , Position :: new( ChunkIdentifier :: new( 0 ) , 0 ) ) ,
380- ] ;
381-
382- sort_events_by_position_descending ( & mut event_ids) ;
383-
384- assert_eq ! (
385- event_ids,
386- & [
387- ( ev1, Position :: new( ChunkIdentifier :: new( 2 ) , 1 ) ) ,
388- ( ev3, Position :: new( ChunkIdentifier :: new( 2 ) , 0 ) ) ,
389- ( ev4, Position :: new( ChunkIdentifier :: new( 1 ) , 1 ) ) ,
390- ( ev2, Position :: new( ChunkIdentifier :: new( 1 ) , 0 ) ) ,
391- ( ev5, Position :: new( ChunkIdentifier :: new( 0 ) , 0 ) ) ,
392- ]
393- ) ;
394- }
395-
396344 #[ async_test]
397345 async fn test_filter_find_duplicates_in_the_input ( ) {
398346 let event_id_0 = owned_event_id ! ( "$ev0" ) ;
@@ -587,11 +535,11 @@ mod tests {
587535 assert_eq ! ( outcome. in_memory_duplicated_event_ids. len( ) , 2 ) ;
588536 assert_eq ! (
589537 outcome. in_memory_duplicated_event_ids[ 0 ] ,
590- ( event_id_3 , Position :: new( ChunkIdentifier :: new( 0 ) , 1 ) )
538+ ( event_id_2 , Position :: new( ChunkIdentifier :: new( 0 ) , 0 ) )
591539 ) ;
592540 assert_eq ! (
593541 outcome. in_memory_duplicated_event_ids[ 1 ] ,
594- ( event_id_2 , Position :: new( ChunkIdentifier :: new( 0 ) , 0 ) )
542+ ( event_id_3 , Position :: new( ChunkIdentifier :: new( 0 ) , 1 ) )
595543 ) ;
596544
597545 // From these 4 events, 2 are duplicated and live in the store only, they have
@@ -601,11 +549,11 @@ mod tests {
601549 assert_eq ! ( outcome. in_store_duplicated_event_ids. len( ) , 2 ) ;
602550 assert_eq ! (
603551 outcome. in_store_duplicated_event_ids[ 0 ] ,
604- ( event_id_1 , Position :: new( ChunkIdentifier :: new( 42 ) , 1 ) )
552+ ( event_id_0 , Position :: new( ChunkIdentifier :: new( 42 ) , 0 ) )
605553 ) ;
606554 assert_eq ! (
607555 outcome. in_store_duplicated_event_ids[ 1 ] ,
608- ( event_id_0 , Position :: new( ChunkIdentifier :: new( 42 ) , 0 ) )
556+ ( event_id_1 , Position :: new( ChunkIdentifier :: new( 42 ) , 1 ) )
609557 ) ;
610558 }
611559
@@ -755,11 +703,11 @@ mod tests {
755703 assert_eq ! ( in_store_duplicated_event_ids. len( ) , 2 ) ;
756704 assert_eq ! (
757705 in_store_duplicated_event_ids[ 0 ] ,
758- ( eid2 . to_owned( ) , Position :: new( ChunkIdentifier :: new( 43 ) , 0 ) )
706+ ( eid1 . to_owned( ) , Position :: new( ChunkIdentifier :: new( 42 ) , 0 ) )
759707 ) ;
760708 assert_eq ! (
761709 in_store_duplicated_event_ids[ 1 ] ,
762- ( eid1 . to_owned( ) , Position :: new( ChunkIdentifier :: new( 42 ) , 0 ) )
710+ ( eid2 . to_owned( ) , Position :: new( ChunkIdentifier :: new( 43 ) , 0 ) )
763711 ) ;
764712 }
765713}
0 commit comments