@@ -790,30 +790,22 @@ impl SledStore {
790
790
}
791
791
} ;
792
792
793
- let final_events: Vec < _ > = events
794
- . iter ( )
795
- . filter ( |e| {
796
- event_id_to_position
797
- . get ( ( room. as_str ( ) , e. event_id ( ) . unwrap ( ) . as_str ( ) ) . encode ( ) )
798
- . transpose ( )
799
- . is_none ( )
800
- } )
801
- . collect ( ) ;
802
-
803
- let duplicated = events. len ( ) - final_events. len ( ) ;
804
-
805
- let current_position = if expandable. start_token_changed
806
- && !expandable. end_token_changed
807
- {
808
- expandable. current_position - duplicated
809
- } else if expandable. end_token_changed && !expandable. start_token_changed {
810
- expandable. current_position + duplicated
811
- } else {
812
- expandable. current_position
813
- } ;
793
+ // Remove events already known from the store
794
+ for event in & events {
795
+ if let Some ( batch) = event_id_to_position
796
+ . remove (
797
+ ( room. as_str ( ) , event. event_id ( ) . unwrap ( ) . as_str ( ) ) . encode ( ) ,
798
+ ) ?
799
+ . map ( EventPosition :: from)
800
+ {
801
+ timeline_events. remove (
802
+ ( room. as_str ( ) , batch. batch_idx , batch. position ) . encode ( ) ,
803
+ ) ?;
804
+ }
805
+ }
814
806
815
- for ( position, event) in final_events . iter ( ) . enumerate ( ) {
816
- let position = position + current_position;
807
+ for ( position, event) in events . iter ( ) . enumerate ( ) {
808
+ let position = position + expandable . current_position ;
817
809
818
810
let old_event = timeline_events. insert (
819
811
( room. as_str ( ) , expandable. batch_idx , position) . encode ( ) ,
@@ -888,7 +880,7 @@ impl SledStore {
888
880
( room. as_str ( ) , timeline. start . as_str ( ) ) . encode ( ) ,
889
881
EventPosition {
890
882
batch_idx : expandable. batch_idx ,
891
- position : current_position,
883
+ position : expandable . current_position ,
892
884
} ,
893
885
) ?;
894
886
}
@@ -904,7 +896,7 @@ impl SledStore {
904
896
( room. as_str ( ) , end. as_str ( ) ) . encode ( ) ,
905
897
EventPosition {
906
898
batch_idx : expandable. batch_idx ,
907
- position : current_position + final_events . len ( ) ,
899
+ position : expandable . current_position + events . len ( ) ,
908
900
} ,
909
901
) ?;
910
902
}
@@ -1980,6 +1972,7 @@ mod test {
1980
1972
. await
1981
1973
. unwrap ( )
1982
1974
. unwrap ( ) ;
1975
+
1983
1976
assert_eq ! ( backward_events. events. len( ) , 9 ) ;
1984
1977
assert_eq ! ( backward_events. token, messages. end. clone( ) ) ;
1985
1978
0 commit comments