Fixes the coverage probably too
This commit is contained in:
parent
f5b293c8a2
commit
31b19a48b7
@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from binascii import hexlify
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
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 hash is the same
|
||||
# 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 (
|
||||
CLASSIFIER_VERSION_KEY in cache_hits
|
||||
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION
|
||||
@ -89,11 +104,12 @@ def set_suggestions_cache(
|
||||
"""
|
||||
if classifier is not None:
|
||||
doc_key = get_suggestion_cache_key(document_id)
|
||||
print(classifier.last_auto_type_hash)
|
||||
cache.set(
|
||||
doc_key,
|
||||
SuggestionCacheData(
|
||||
classifier.FORMAT_VERSION,
|
||||
classifier.last_auto_type_hash.hex(),
|
||||
hexlify(classifier.last_auto_type_hash).decode(),
|
||||
suggestions,
|
||||
),
|
||||
timeout,
|
||||
|
@ -1317,7 +1317,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
|
||||
last_modified = timezone.now()
|
||||
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(
|
||||
CLASSIFIER_VERSION_KEY,
|
||||
DocumentClassifier.FORMAT_VERSION,
|
||||
@ -1356,7 +1356,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
self.assertIn("ETag", response.headers)
|
||||
self.assertEqual(
|
||||
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/")
|
||||
|
@ -421,14 +421,15 @@ class DocumentViewSet(
|
||||
|
||||
document_cached_metadata = get_metadata_cache(doc.pk)
|
||||
|
||||
archive_metadata = None
|
||||
archive_filesize = None
|
||||
if document_cached_metadata is not None:
|
||||
original_metadata = document_cached_metadata.original_metadata
|
||||
archive_metadata = document_cached_metadata.archive_metadata
|
||||
refresh_metadata_cache(doc.pk)
|
||||
else:
|
||||
original_metadata = self.get_metadata(doc.source_path, doc.mime_type)
|
||||
archive_metadata = None
|
||||
archive_filesize = None
|
||||
|
||||
if doc.has_archive_version:
|
||||
archive_filesize = self.get_filesize(doc.archive_path)
|
||||
archive_metadata = self.get_metadata(
|
||||
|
Loading…
x
Reference in New Issue
Block a user