@@ -4,34 +4,11 @@ use rivet_api_builder::{
44 ApiError ,
55 extract:: { Extension , Json , Query } ,
66} ;
7- use rivet_api_types:: pagination:: Pagination ;
7+ use rivet_api_types:: { actors :: list :: * , pagination:: Pagination } ;
88use rivet_api_util:: fanout_to_datacenters;
9- use serde:: { Deserialize , Serialize } ;
10- use utoipa:: { IntoParams , ToSchema } ;
119
1210use crate :: { actors:: utils:: fetch_actors_by_ids, ctx:: ApiCtx , errors} ;
1311
14- #[ derive( Debug , Serialize , Deserialize , Clone , IntoParams ) ]
15- #[ serde( deny_unknown_fields) ]
16- #[ into_params( parameter_in = Query ) ]
17- pub struct ListQuery {
18- pub namespace : String ,
19- pub name : Option < String > ,
20- pub key : Option < String > ,
21- pub actor_ids : Option < String > ,
22- pub include_destroyed : Option < bool > ,
23- pub limit : Option < usize > ,
24- pub cursor : Option < String > ,
25- }
26-
27- #[ derive( Serialize , Deserialize , ToSchema ) ]
28- #[ serde( deny_unknown_fields) ]
29- #[ schema( as = ActorsListResponse ) ]
30- pub struct ListResponse {
31- pub actors : Vec < rivet_types:: actors:: Actor > ,
32- pub pagination : Pagination ,
33- }
34-
3512/// ## Datacenter Round Trips
3613///
3714/// **If key is some & `include_destroyed` is false**
@@ -123,15 +100,25 @@ async fn list_inner(ctx: ApiCtx, query: ListQuery) -> Result<ListResponse> {
123100 . ok_or_else ( || namespace:: errors:: Namespace :: NotFound . build ( ) ) ?;
124101
125102 // Fetch actors
126- let actors = fetch_actors_by_ids (
103+ let mut actors = fetch_actors_by_ids (
127104 & ctx,
128105 actor_ids,
129106 query. namespace . clone ( ) ,
130107 query. include_destroyed ,
131- query . limit ,
108+ None , // Don't apply limit in fetch, we'll apply it after cursor filtering
132109 )
133110 . await ?;
134111
112+ // Apply cursor filtering if provided
113+ if let Some ( cursor_str) = & query. cursor {
114+ let cursor_ts: i64 = cursor_str. parse ( ) . context ( "invalid cursor format" ) ?;
115+ actors. retain ( |actor| actor. create_ts < cursor_ts) ;
116+ }
117+
118+ // Apply limit after cursor filtering
119+ let limit = query. limit . unwrap_or ( 100 ) ;
120+ actors. truncate ( limit) ;
121+
135122 let cursor = actors. last ( ) . map ( |x| x. create_ts . to_string ( ) ) ;
136123
137124 Ok ( ListResponse {
@@ -196,40 +183,25 @@ async fn list_inner(ctx: ApiCtx, query: ListQuery) -> Result<ListResponse> {
196183 . build ( ) ) ;
197184 }
198185
199- // Prepare peer query for local handler
200- let peer_query = rivet_api_types:: actors:: list:: ListQuery {
201- namespace : query. namespace . clone ( ) ,
202- name : Some ( query. name . as_ref ( ) . unwrap ( ) . clone ( ) ) ,
203- key : query. key . clone ( ) ,
204- actor_ids : None ,
205- include_destroyed : query. include_destroyed ,
206- limit : query. limit ,
207- cursor : query. cursor . clone ( ) ,
208- } ;
186+ let limit = query. limit . unwrap_or ( 100 ) ;
209187
210188 // Fanout to all datacenters
211- let mut actors = fanout_to_datacenters :: <
212- rivet_api_types:: actors:: list:: ListResponse ,
213- _ ,
214- _ ,
215- _ ,
216- _ ,
217- Vec < rivet_types:: actors:: Actor > ,
218- > (
219- ctx. into ( ) ,
220- "/actors" ,
221- peer_query,
222- |ctx, query| async move { rivet_api_peer:: actors:: list:: list ( ctx, ( ) , query) . await } ,
223- |_, res, agg| agg. extend ( res. actors ) ,
224- )
225- . await ?;
189+ let mut actors =
190+ fanout_to_datacenters :: < ListResponse , _ , _ , _ , _ , Vec < rivet_types:: actors:: Actor > > (
191+ ctx. into ( ) ,
192+ "/actors" ,
193+ query,
194+ |ctx, query| async move { rivet_api_peer:: actors:: list:: list ( ctx, ( ) , query) . await } ,
195+ |_, res, agg| agg. extend ( res. actors ) ,
196+ )
197+ . await ?;
226198
227199 // Sort by create ts desc
228200 actors. sort_by_cached_key ( |x| std:: cmp:: Reverse ( x. create_ts ) ) ;
229201
230202 // Shorten array since returning all actors from all regions could end up returning `regions *
231203 // limit` results, which is a lot.
232- actors. truncate ( query . limit . unwrap_or ( 100 ) ) ;
204+ actors. truncate ( limit) ;
233205
234206 let cursor = actors. last ( ) . map ( |x| x. create_ts . to_string ( ) ) ;
235207
0 commit comments