Perf: avoid per-instance CustomField reload in DocumentMetadataOverrides

send_websocket_document_updated calls document.refresh_from_db()
before building overrides, which drops the custom_fields prefetch
(and its select_related("field")) set up by the view's queryset.
DocumentMetadataOverrides.from_document() then lazily reloads field
once per custom field instance. Since from_document() can't rely on
the caller having a prefetched document, select_related explicitly at
the point of use instead.
This commit is contained in:
Trenton Holmes
2026-08-23 17:33:05 -07:00
parent 0a466c9fcf
commit 4ccb34a70b
2 changed files with 59 additions and 1 deletions
+1 -1
View File
@@ -126,7 +126,7 @@ class DocumentMetadataOverrides:
)
overrides.custom_fields = {
custom_field.field.id: custom_field.value
for custom_field in doc.custom_fields.all()
for custom_field in doc.custom_fields.select_related("field").all()
}
groups_with_perms = get_groups_with_perms(