@@ -21,6 +21,16 @@ pub struct EventPaginationCursor {
2121 pub event_id : ShortEventId ,
2222}
2323
24+ impl EventPaginationCursor {
25+ pub const ZERO : Self = Self {
26+ ts : Timestamp :: ZERO ,
27+ event_id : ShortEventId :: ZERO ,
28+ } ;
29+ pub const MAX : Self = Self {
30+ ts : Timestamp :: MAX ,
31+ event_id : ShortEventId :: MAX ,
32+ } ;
33+ }
2434#[ derive( Clone ) ]
2535pub struct SocialPostRecord < C > {
2636 pub ts : Timestamp ,
@@ -105,7 +115,10 @@ impl Database {
105115 upper_bound : Option < EventPaginationCursor > ,
106116 limit : usize ,
107117 filter_fn : impl Fn ( & SocialPostRecord < SocialPost > ) -> bool + Send + ' static ,
108- ) -> Vec < SocialPostRecord < content_kind:: SocialPost > > {
118+ ) -> (
119+ Vec < SocialPostRecord < content_kind:: SocialPost > > ,
120+ EventPaginationCursor ,
121+ ) {
109122 let upper_bound = upper_bound
110123 . map ( |b| ( b. ts , b. event_id ) )
111124 . unwrap_or ( ( Timestamp :: MAX , ShortEventId :: MAX ) ) ;
@@ -116,6 +129,7 @@ impl Database {
116129 let events_content_table = tx. open_table ( & events_content:: TABLE ) ?;
117130
118131 let mut ret = vec ! [ ] ;
132+ let mut last = EventPaginationCursor { ts : Timestamp :: ZERO , event_id : ShortEventId :: ZERO } ;
119133
120134 for event in social_posts_by_time_table
121135 . range ( & ( Timestamp :: ZERO , ShortEventId :: ZERO ) ..& upper_bound) ?
@@ -127,6 +141,7 @@ impl Database {
127141 let ( k, _) = event?;
128142 let ( ts, event_id) = k. value ( ) ;
129143
144+ last = EventPaginationCursor { ts, event_id} ;
130145
131146 let Some ( content_state) =
132147 Database :: get_event_content_tx ( event_id, & events_content_table) ?
@@ -168,7 +183,7 @@ impl Database {
168183 ret. push ( social_post_record) ;
169184 }
170185
171- Ok ( ret)
186+ Ok ( ( ret, last ) )
172187 } )
173188 . await
174189 . expect ( "Storage error" )
@@ -179,7 +194,10 @@ impl Database {
179194 lower_bound : Option < EventPaginationCursor > ,
180195 limit : usize ,
181196 filter_fn : impl Fn ( & SocialPostRecord < SocialPost > ) -> bool + Send + ' static ,
182- ) -> Vec < SocialPostRecord < content_kind:: SocialPost > > {
197+ ) -> (
198+ Vec < SocialPostRecord < content_kind:: SocialPost > > ,
199+ EventPaginationCursor ,
200+ ) {
183201 let lower_bound = lower_bound
184202 . map ( |b| ( b. ts , b. event_id ) )
185203 . unwrap_or ( ( Timestamp :: ZERO , ShortEventId :: ZERO ) ) ;
@@ -190,6 +208,7 @@ impl Database {
190208 let events_content_table = tx. open_table ( & events_content:: TABLE ) ?;
191209
192210 let mut ret = vec ! [ ] ;
211+ let mut last = EventPaginationCursor { ts : Timestamp :: MAX , event_id : ShortEventId :: MAX } ;
193212
194213 for event in social_posts_by_time_table
195214 . range ( & lower_bound..& ( Timestamp :: MAX , ShortEventId :: MAX ) ) ?
@@ -201,6 +220,12 @@ impl Database {
201220 let ( k, _) = event?;
202221 let ( ts, event_id) = k. value ( ) ;
203222
223+ // Since we don't have exclusive lower bound range, we need to skip it manually
224+ if ( ts, event_id) == lower_bound {
225+ continue ;
226+ }
227+
228+ last = EventPaginationCursor { ts, event_id} ;
204229
205230 let Some ( content_state) =
206231 Database :: get_event_content_tx ( event_id, & events_content_table) ?
@@ -243,7 +268,7 @@ impl Database {
243268
244269 }
245270
246- Ok ( ret)
271+ Ok ( ( ret, last ) )
247272 } )
248273 . await
249274 . expect ( "Storage error" )
0 commit comments