Skip to content

Fix N+1 Query Problem in Collection Repositories #10

@caleb-vanlue

Description

@caleb-vanlue

The UserCollectionRepository.findByUserIdSorted() and UserWantlistRepository.findByUserIdSorted() methods trigger separate queries for each release relation. With large collections, this causes response times to increase linearly, risks database connection pool exhaustion, and creates poor performance for users with 100+ items in their collections.

Proposed Solution

Use TypeORM's leftJoinAndSelect for eager loading of release data in a single query. Alternatively, implement the DataLoader pattern for batched loading of relations. Add query performance monitoring to track improvements and ensure consistent performance regardless of collection size.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions