You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix N+1 query problem in GET /api/v1/changesets/ (#744)
The DRF Serializer for the Changeset model was using obj.tags.filter()
and obj.reasons.filter() to filter the lists of reasons and tags
(only showing enabled ones to non-staff users). This had the probably
unexpected consequence of generating an additional two database
queries for each changeset in the resulting list. The reasons and tags
related fields were being prefetched, but prefetching only works for
iterating the entire relation.
The fix for this problem is straightforward: instead of using .filter(),
we can just filter the reasons and tags in Python. This allows the
prefetching to work as intended and avoids the additional queries.
0 commit comments