mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-01 09:44:19 +00:00
Fix: count notes during iteration instead of issuing extra COUNT(*) query
document.notes.count() bypasses the prefetch cache and hits the DB on every document during rebuild. Counting in the existing loop eliminates the query entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -269,7 +269,9 @@ class TantivyBackend:
|
||||
|
||||
# Notes — JSON for structured queries (notes.user:alice, notes.note:text),
|
||||
# companion text field for default full-text search.
|
||||
num_notes = 0
|
||||
for note in document.notes.all():
|
||||
num_notes += 1
|
||||
note_data: dict[str, str] = {"note": note.note}
|
||||
if note.user:
|
||||
note_data["user"] = note.user.username
|
||||
@@ -305,7 +307,7 @@ class TantivyBackend:
|
||||
if document.page_count is not None:
|
||||
doc.add_unsigned("page_count", document.page_count)
|
||||
|
||||
doc.add_unsigned("num_notes", document.notes.count())
|
||||
doc.add_unsigned("num_notes", num_notes)
|
||||
|
||||
# Owner
|
||||
if document.owner_id:
|
||||
|
||||
Reference in New Issue
Block a user