File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,16 +18,27 @@ export class PostRepository extends AbstractRepository<PostModel> {
1818 . getMany ( ) ;
1919 }
2020
21- public async getAllPostsPaginated ( skip :number , limit :number ) : Promise < PostModel [ ] > {
21+ public async getAllPostsPaginated ( skip : number , limit : number ) : Promise < PostModel [ ] > {
22+ // Step 1: Get paginated post IDs
23+ const postIds = await this . repository
24+ . createQueryBuilder ( "post" )
25+ . select ( "post.id" )
26+ . where ( "post.archive = false" )
27+ . orderBy ( "post.createdAt" , "DESC" )
28+ . skip ( skip )
29+ . take ( limit )
30+ . getMany ( ) ;
31+
32+ const ids = postIds . map ( post => post . id ) ;
33+ if ( ids . length === 0 ) return [ ] ;
34+
35+ // Step 2: Fetch full posts with relations
2236 return await this . repository
2337 . createQueryBuilder ( "post" )
2438 . leftJoinAndSelect ( "post.user" , "user" )
2539 . leftJoinAndSelect ( "post.categories" , "categories" )
26- . where ( "post.archive = false" )
27- . orderBy ( "post.created" , "DESC" )
28- . skip ( skip ) // Skip previous pages
29- . take ( limit )
30-
40+ . where ( "post.id IN (:...ids)" , { ids } )
41+ . orderBy ( "post.createdAt" , "DESC" )
3142 . getMany ( ) ;
3243 }
3344
You can’t perform that action at this time.
0 commit comments