From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:41:33 +0000 (-0700) Subject: Cache classifier loading with lru_cache X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10728%2Fhead;p=thirdparty%2Fpaperless-ngx.git Cache classifier loading with lru_cache --- diff --git a/src/documents/classifier.py b/src/documents/classifier.py index 155f5b20c..02094fa74 100644 --- a/src/documents/classifier.py +++ b/src/documents/classifier.py @@ -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(