@@ -787,30 +787,22 @@ impl SledStore {
787
787
}
788
788
} ;
789
789
790
- let final_events: Vec < _ > = events
791
- . iter ( )
792
- . filter ( |e| {
793
- event_id_to_position
794
- . get ( ( room. as_str ( ) , e. event_id ( ) . unwrap ( ) . as_str ( ) ) . encode ( ) )
795
- . transpose ( )
796
- . is_none ( )
797
- } )
798
- . collect ( ) ;
799
-
800
- let duplicated = events. len ( ) - final_events. len ( ) ;
801
-
802
- let current_position = if expandable. start_token_changed
803
- && !expandable. end_token_changed
804
- {
805
- expandable. current_position - duplicated
806
- } else if expandable. end_token_changed && !expandable. start_token_changed {
807
- expandable. current_position + duplicated
808
- } else {
809
- expandable. current_position
810
- } ;
790
+ // Remove events already known from the store
791
+ for event in & events {
792
+ if let Some ( batch) = event_id_to_position
793
+ . remove (
794
+ ( room. as_str ( ) , event. event_id ( ) . unwrap ( ) . as_str ( ) ) . encode ( ) ,
795
+ ) ?
796
+ . map ( EventPosition :: from)
797
+ {
798
+ timeline_events. remove (
799
+ ( room. as_str ( ) , batch. batch_idx , batch. position ) . encode ( ) ,
800
+ ) ?;
801
+ }
802
+ }
811
803
812
- for ( position, event) in final_events . iter ( ) . enumerate ( ) {
813
- let position = position + current_position;
804
+ for ( position, event) in events . iter ( ) . enumerate ( ) {
805
+ let position = position + expandable . current_position ;
814
806
815
807
let old_event = timeline_events. insert (
816
808
( room. as_str ( ) , expandable. batch_idx , position) . encode ( ) ,
@@ -875,7 +867,7 @@ impl SledStore {
875
867
( room. as_str ( ) , timeline. start . as_str ( ) ) . encode ( ) ,
876
868
EventPosition {
877
869
batch_idx : expandable. batch_idx ,
878
- position : current_position,
870
+ position : expandable . current_position ,
879
871
} ,
880
872
) ?;
881
873
}
@@ -891,7 +883,7 @@ impl SledStore {
891
883
( room. as_str ( ) , end. as_str ( ) ) . encode ( ) ,
892
884
EventPosition {
893
885
batch_idx : expandable. batch_idx ,
894
- position : current_position + final_events . len ( ) ,
886
+ position : expandable . current_position + events . len ( ) ,
895
887
} ,
896
888
) ?;
897
889
}
@@ -1978,6 +1970,7 @@ mod test {
1978
1970
. await
1979
1971
. unwrap ( )
1980
1972
. unwrap ( ) ;
1973
+
1981
1974
assert_eq ! ( backward_events. events. len( ) , 9 ) ;
1982
1975
assert_eq ! ( backward_events. token, messages. end. clone( ) ) ;
1983
1976
0 commit comments