Cache classifier loading with lru_cache

This commit is contained in:
shamoon
2025-08-31 15:41:33 -07:00
parent 569cc46a43
commit fc5b9bdf59

View 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(