Fixes the coverage probably too
This commit is contained in:
parent
f5b293c8a2
commit
31b19a48b7
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from binascii import hexlify
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from typing import Final
|
from typing import Final
|
||||||
@ -61,6 +62,20 @@ def get_suggestion_cache(document_id: int) -> Optional[SuggestionCacheData]:
|
|||||||
# The classifier format is the same
|
# The classifier format is the same
|
||||||
# The classifier hash is the same
|
# The classifier hash is the same
|
||||||
# Then the suggestions can be used
|
# Then the suggestions can be used
|
||||||
|
print(CLASSIFIER_VERSION_KEY in cache_hits)
|
||||||
|
if CLASSIFIER_VERSION_KEY in cache_hits:
|
||||||
|
print(
|
||||||
|
cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION,
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
cache_hits[CLASSIFIER_VERSION_KEY]
|
||||||
|
== doc_suggestions.classifier_version,
|
||||||
|
)
|
||||||
|
print(CLASSIFIER_HASH_KEY in cache_hits)
|
||||||
|
if CLASSIFIER_HASH_KEY in cache_hits:
|
||||||
|
print(cache_hits[CLASSIFIER_HASH_KEY])
|
||||||
|
print(doc_suggestions.classifier_hash)
|
||||||
|
print(cache_hits[CLASSIFIER_HASH_KEY] == doc_suggestions.classifier_hash)
|
||||||
if (
|
if (
|
||||||
CLASSIFIER_VERSION_KEY in cache_hits
|
CLASSIFIER_VERSION_KEY in cache_hits
|
||||||
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION
|
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION
|
||||||
@ -89,11 +104,12 @@ def set_suggestions_cache(
|
|||||||
"""
|
"""
|
||||||
if classifier is not None:
|
if classifier is not None:
|
||||||
doc_key = get_suggestion_cache_key(document_id)
|
doc_key = get_suggestion_cache_key(document_id)
|
||||||
|
print(classifier.last_auto_type_hash)
|
||||||
cache.set(
|
cache.set(
|
||||||
doc_key,
|
doc_key,
|
||||||
SuggestionCacheData(
|
SuggestionCacheData(
|
||||||
classifier.FORMAT_VERSION,
|
classifier.FORMAT_VERSION,
|
||||||
classifier.last_auto_type_hash.hex(),
|
hexlify(classifier.last_auto_type_hash).decode(),
|
||||||
suggestions,
|
suggestions,
|
||||||
),
|
),
|
||||||
timeout,
|
timeout,
|
||||||
|
@ -1317,7 +1317,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
|
|
||||||
last_modified = timezone.now()
|
last_modified = timezone.now()
|
||||||
cache.set(CLASSIFIER_MODIFIED_KEY, last_modified, CACHE_50_MINUTES)
|
cache.set(CLASSIFIER_MODIFIED_KEY, last_modified, CACHE_50_MINUTES)
|
||||||
cache.set(CLASSIFIER_HASH_KEY, classifier_checksum, CACHE_50_MINUTES)
|
cache.set(CLASSIFIER_HASH_KEY, classifier_checksum.decode(), CACHE_50_MINUTES)
|
||||||
cache.set(
|
cache.set(
|
||||||
CLASSIFIER_VERSION_KEY,
|
CLASSIFIER_VERSION_KEY,
|
||||||
DocumentClassifier.FORMAT_VERSION,
|
DocumentClassifier.FORMAT_VERSION,
|
||||||
@ -1356,7 +1356,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
self.assertIn("ETag", response.headers)
|
self.assertIn("ETag", response.headers)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.headers["ETag"],
|
response.headers["ETag"],
|
||||||
f'"{classifier_checksum}:{settings.NUMBER_OF_SUGGESTED_DATES}"',
|
f'"{classifier_checksum.decode()}:{settings.NUMBER_OF_SUGGESTED_DATES}"',
|
||||||
)
|
)
|
||||||
|
|
||||||
response = self.client.get(f"/api/documents/{doc.pk}/suggestions/")
|
response = self.client.get(f"/api/documents/{doc.pk}/suggestions/")
|
||||||
|
@ -421,14 +421,15 @@ class DocumentViewSet(
|
|||||||
|
|
||||||
document_cached_metadata = get_metadata_cache(doc.pk)
|
document_cached_metadata = get_metadata_cache(doc.pk)
|
||||||
|
|
||||||
|
archive_metadata = None
|
||||||
|
archive_filesize = None
|
||||||
if document_cached_metadata is not None:
|
if document_cached_metadata is not None:
|
||||||
original_metadata = document_cached_metadata.original_metadata
|
original_metadata = document_cached_metadata.original_metadata
|
||||||
archive_metadata = document_cached_metadata.archive_metadata
|
archive_metadata = document_cached_metadata.archive_metadata
|
||||||
refresh_metadata_cache(doc.pk)
|
refresh_metadata_cache(doc.pk)
|
||||||
else:
|
else:
|
||||||
original_metadata = self.get_metadata(doc.source_path, doc.mime_type)
|
original_metadata = self.get_metadata(doc.source_path, doc.mime_type)
|
||||||
archive_metadata = None
|
|
||||||
archive_filesize = None
|
|
||||||
if doc.has_archive_version:
|
if doc.has_archive_version:
|
||||||
archive_filesize = self.get_filesize(doc.archive_path)
|
archive_filesize = self.get_filesize(doc.archive_path)
|
||||||
archive_metadata = self.get_metadata(
|
archive_metadata = self.get_metadata(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user