@@ -96,10 +96,29 @@ func (c *CollectionsManager) Delete(ctx context.Context, id int64) error {
9696}
9797
9898func (c * CollectionsManager ) List (ctx context.Context ) ([]CollectionEntity , error ) {
99- log .Debug ("listing all collections" )
100- collections , err := c .DB . GetAllCollections (ctx )
99+ log .Debug ("listing all collections with default pagination " )
100+ paginated , err := c .ListPaginated (ctx , 50 , 0 )
101101 if err != nil {
102- log .Error ("failed to list collections" , "error" , err )
102+ return nil , err
103+ }
104+ return paginated .Collections , nil
105+ }
106+
107+ func (c * CollectionsManager ) ListPaginated (ctx context.Context , limit , offset int64 ) (* PaginatedCollections , error ) {
108+ log .Debug ("listing paginated collections" , "limit" , limit , "offset" , offset )
109+
110+ total , err := c .DB .CountCollections (ctx )
111+ if err != nil {
112+ log .Error ("failed to count collections" , "error" , err )
113+ return nil , err
114+ }
115+
116+ collections , err := c .DB .GetCollectionsPaginated (ctx , database.GetCollectionsPaginatedParams {
117+ Limit : limit ,
118+ Offset : offset ,
119+ })
120+ if err != nil {
121+ log .Error ("failed to get paginated collections" , "limit" , limit , "offset" , offset , "error" , err )
103122 return nil , err
104123 }
105124
@@ -108,6 +127,17 @@ func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, erro
108127 entities [i ] = CollectionEntity {Collection : collection }
109128 }
110129
111- log .Debug ("listed collections" , "count" , len (entities ))
112- return entities , nil
130+ hasNext := offset + int64 (len (collections )) < total
131+ hasPrev := offset > 0
132+
133+ log .Debug ("retrieved paginated collections" , "total" , total , "returned" , len (entities ), "has_next" , hasNext , "has_prev" , hasPrev )
134+
135+ return & PaginatedCollections {
136+ Collections : entities ,
137+ Total : total ,
138+ Offset : offset ,
139+ Limit : limit ,
140+ HasNext : hasNext ,
141+ HasPrev : hasPrev ,
142+ }, nil
113143}
0 commit comments