← Back to Changelog
ImprovementApril 16, 2026

resolve N+1 query in rooms list endpoint

  • Fixed N+1 query on /api/v1/rooms/ where up to 6 DB queries were executed per room for the current user's membership
  • Added a Prefetch with to_attr in RoomViewSet.get_queryset to batch-fetch the current user's active membership for all rooms in a single query
  • Updated Room model and RoomSerializer to use the prefetch cache, with graceful fallback to DB queries for non-list contexts (detail views, WebSocket consumers, etc.)

Eliminates up to 6N queries (N = number of rooms), replacing them with 1 additional prefetch query.