This PR addresses the unbounded reads in AchievementsService. Methods that used to retrieve the entire sets of achievements or user progress now accept pagination parameters and perform bounded queries to avoid loading large lists into memory. Additionally, the achievement definition set is now cached and getUserAchievementOverview performs an aggregated query instead of retrieving arrays into memory to calculate totals.
- Added pagination parameters (
query?: PaginationQueryDto) togetAllAchievements,getAchievementsByType,getUserAllProgress, andgetUserAchievements. - Updated these methods to return
OffsetPaginatedResponseusingbuildOffsetResponse, and implementedskip/takelogic in TypeORM queries. - Injected
CacheManagerto cachetotal_achievementsand invalidated the cache (achievements_definitions) on mutations (createAchievement,updateAchievement,deactivateAchievement). - Refactored
getUserAchievementOverviewto replace lines 472-476 (loading all active achievements and all user achievements into arrays). It now usesCacheManagerfortotalAchievementsand a singlecreateQueryBuilderaggregation to calculateunlockedCount,totalPoints, andtotalExperience. - Ensured indexes exist on
userIdwithin the progress tracking components for optimization.
- All achievement list endpoints return bounded pages.
- Definition reads are served from cache between mutations.
- The definitions-plus-progress path issues one query rather than two full reads.
- User-scoped achievement lookups are index-backed.