Implement prefetching for ClusterTaggableManager #180
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit implements prefetching for ClusterTaggableManager so that prefetch_related works properly:
Currently the above code functions properly but does not actually leverage the prefetching; each call to
place.tags.all()
re-queries the database for each place's tags, instead of using the list previously fetched with theprefetch_related("tags")
.This commit properly implements prefetch_related to avoid those duplicate queries.
To test, run tox.
This change requires a bit of complexity due to a change in Django 5.0+ (which is tested under tox but not currently tested in GitHub Actions): As documented in https://code.djangoproject.com/ticket/31486, it's no longer possible to pass unsaved model instances to related filters, preventing calls like:
This requires some special handling to continue to support querying tags on unsaved model instances:
Please see comments in taggit.py for additional detail.
Closes #38, and may also address wagtail/wagtail#6044.