]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Cache classifier loading with lru_cache 10728/head
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sun, 31 Aug 2025 22:41:33 +0000 (15:41 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sun, 31 Aug 2025 22:41:33 +0000 (15:41 -0700)
src/documents/classifier.py

index 155f5b20c6754d328af751e0163aaea7333cb005..02094fa744e0fbb3aa54bf51f84c50196f72abeb 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import pickle
 import re
 import warnings
+from functools import lru_cache
 from hashlib import sha256
 from pathlib import Path
 from typing import TYPE_CHECKING
@@ -52,6 +53,7 @@ class ClassifierModelCorruptError(Exception):
     pass
 
 
+@lru_cache(maxsize=1)
 def load_classifier(*, raise_exception: bool = False) -> DocumentClassifier | None:
     if not settings.MODEL_FILE.is_file():
         logger.debug(