dont add extra content query

This commit is contained in:
shamoon
2026-02-12 22:45:23 -08:00
parent 2bb73627d6
commit c929f1c94c
3 changed files with 19 additions and 11 deletions

View File

@@ -50,7 +50,6 @@ from documents.models import CustomFieldInstance
from documents.models import Document from documents.models import Document
from documents.models import Note from documents.models import Note
from documents.models import User from documents.models import User
from documents.versioning import get_latest_version_for_root
if TYPE_CHECKING: if TYPE_CHECKING:
from django.db.models import QuerySet from django.db.models import QuerySet
@@ -159,7 +158,11 @@ def open_index_searcher() -> Searcher:
searcher.close() searcher.close()
def update_document(writer: AsyncWriter, doc: Document) -> None: def update_document(
writer: AsyncWriter,
doc: Document,
effective_content: str | None = None,
) -> None:
tags = ",".join([t.name for t in doc.tags.all()]) tags = ",".join([t.name for t in doc.tags.all()])
tags_ids = ",".join([str(t.id) for t in doc.tags.all()]) tags_ids = ",".join([str(t.id) for t in doc.tags.all()])
notes = ",".join([str(c.note) for c in Note.objects.filter(document=doc)]) notes = ",".join([str(c.note) for c in Note.objects.filter(document=doc)])
@@ -186,15 +189,10 @@ def update_document(writer: AsyncWriter, doc: Document) -> None:
only_with_perms_in=["view_document"], only_with_perms_in=["view_document"],
) )
viewer_ids: str = ",".join([str(u.id) for u in users_with_perms]) viewer_ids: str = ",".join([str(u.id) for u in users_with_perms])
effective_content = (
get_latest_version_for_root(doc).content
if doc.root_document_id is None
else doc.content
)
writer.update_document( writer.update_document(
id=doc.pk, id=doc.pk,
title=doc.title, title=doc.title,
content=effective_content, content=effective_content or doc.content,
correspondent=doc.correspondent.name if doc.correspondent else None, correspondent=doc.correspondent.name if doc.correspondent else None,
correspondent_id=doc.correspondent.id if doc.correspondent else None, correspondent_id=doc.correspondent.id if doc.correspondent else None,
has_correspondent=doc.correspondent is not None, has_correspondent=doc.correspondent is not None,
@@ -237,9 +235,12 @@ def remove_document_by_id(writer: AsyncWriter, doc_id) -> None:
writer.delete_by_term("id", doc_id) writer.delete_by_term("id", doc_id)
def add_or_update_document(document: Document) -> None: def add_or_update_document(
document: Document,
effective_content: str | None = None,
) -> None:
with open_index_writer() as writer: with open_index_writer() as writer:
update_document(writer, document) update_document(writer, document, effective_content=effective_content)
def remove_document_from_index(document: Document) -> None: def remove_document_from_index(document: Document) -> None:

View File

@@ -724,7 +724,10 @@ def add_to_index(sender, document, **kwargs) -> None:
index.add_or_update_document(document) index.add_or_update_document(document)
if document.root_document_id is not None and document.root_document is not None: if document.root_document_id is not None and document.root_document is not None:
# keep in sync when a new version is consumed. # keep in sync when a new version is consumed.
index.add_or_update_document(document.root_document) index.add_or_update_document(
document.root_document,
effective_content=document.content,
)
def run_workflows_added( def run_workflows_added(

View File

@@ -232,3 +232,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
self.assertEqual(add.call_count, 2) self.assertEqual(add.call_count, 2)
self.assertEqual(add.call_args_list[0].args[0].id, version.id) self.assertEqual(add.call_args_list[0].args[0].id, version.id)
self.assertEqual(add.call_args_list[1].args[0].id, root.id) self.assertEqual(add.call_args_list[1].args[0].id, root.id)
self.assertEqual(
add.call_args_list[1].kwargs,
{"effective_content": version.content},
)