mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-04-13 03:28:51 +00:00
Compare commits
1 Commits
fix/sanity
...
fix/matchi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c627b12aa |
@@ -650,6 +650,10 @@ class ConsumerPlugin(
|
||||
# If we get here, it was successful. Proceed with post-consume
|
||||
# hooks. If they fail, nothing will get changed.
|
||||
|
||||
document = Document.objects.prefetch_related("versions").get(
|
||||
pk=document.pk,
|
||||
)
|
||||
|
||||
document_consumption_finished.send(
|
||||
sender=self.__class__,
|
||||
document=document,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -182,9 +182,8 @@ def _check_thumbnail(
|
||||
present_files: set[Path],
|
||||
) -> None:
|
||||
"""Verify the thumbnail exists and is readable."""
|
||||
# doc.thumbnail_path already returns a resolved Path; no need to re-resolve.
|
||||
thumbnail_path: Final[Path] = doc.thumbnail_path
|
||||
if not thumbnail_path.is_file():
|
||||
thumbnail_path: Final[Path] = Path(doc.thumbnail_path).resolve()
|
||||
if not thumbnail_path.exists() or not thumbnail_path.is_file():
|
||||
messages.error(doc.pk, "Thumbnail of document does not exist.")
|
||||
return
|
||||
|
||||
@@ -201,9 +200,8 @@ def _check_original(
|
||||
present_files: set[Path],
|
||||
) -> None:
|
||||
"""Verify the original file exists, is readable, and has matching checksum."""
|
||||
# doc.source_path already returns a resolved Path; no need to re-resolve.
|
||||
source_path: Final[Path] = doc.source_path
|
||||
if not source_path.is_file():
|
||||
source_path: Final[Path] = Path(doc.source_path).resolve()
|
||||
if not source_path.exists() or not source_path.is_file():
|
||||
messages.error(doc.pk, "Original of document does not exist.")
|
||||
return
|
||||
|
||||
@@ -239,9 +237,8 @@ def _check_archive(
|
||||
elif doc.has_archive_version:
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(doc.archive_path, Path)
|
||||
# doc.archive_path already returns a resolved Path; no need to re-resolve.
|
||||
archive_path: Final[Path] = doc.archive_path # type: ignore[assignment]
|
||||
if not archive_path.is_file():
|
||||
archive_path: Final[Path] = Path(doc.archive_path).resolve()
|
||||
if not archive_path.exists() or not archive_path.is_file():
|
||||
messages.error(doc.pk, "Archived version of document does not exist.")
|
||||
return
|
||||
|
||||
@@ -317,15 +314,7 @@ def check_sanity(
|
||||
messages = SanityCheckMessages()
|
||||
present_files = _build_present_files()
|
||||
|
||||
documents = Document.global_objects.only(
|
||||
"pk",
|
||||
"filename",
|
||||
"mime_type",
|
||||
"checksum",
|
||||
"archive_checksum",
|
||||
"archive_filename",
|
||||
"content",
|
||||
).iterator(chunk_size=500)
|
||||
documents = Document.global_objects.all()
|
||||
for doc in iter_wrapper(documents):
|
||||
_check_document(doc, messages, present_files)
|
||||
|
||||
|
||||
@@ -1248,7 +1248,10 @@ class DocumentViewSet(
|
||||
),
|
||||
)
|
||||
def suggestions(self, request, pk=None):
|
||||
doc = get_object_or_404(Document.objects.select_related("owner"), pk=pk)
|
||||
doc = get_object_or_404(
|
||||
Document.objects.select_related("owner").prefetch_related("versions"),
|
||||
pk=pk,
|
||||
)
|
||||
if request.user is not None and not has_perms_owner_aware(
|
||||
request.user,
|
||||
"view_document",
|
||||
|
||||
Reference in New Issue
Block a user