Fixes an N+1 query in matching with the version content fetching by prefetching versions (#12562)

This commit is contained in:
Trenton H authored and GitHub committed 2026-04-13 13:10:28 -07:00
1 parent 54d5269145
commit 8c1225e120
3 files changed
+12 -2

No files matched your search

+4 -1
View File
@@ -381,7 +381,10 @@ class Document(SoftDeleteModel, ModelWithOwner): # type: ignore[django-manager-
if isinstance(prefetched_cache, dict)
else None
)
if prefetched_versions:
if prefetched_versions is not None:
# Empty list means prefetch ran and found no versions — use own content.
if not prefetched_versions:
return self.content
latest_prefetched = max(prefetched_versions, key=lambda doc: doc.id)
return latest_prefetched.content