A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Enhancement: allow regex timeout configuration (#14085)
shamoonc9a560790274
diff --git a/docs/configuration.md b/docs/configuration.mdindex e045af077..0068a325d 100644--- a/docs/configuration.md+++ b/docs/configuration.md@@ -1209,6 +1209,14 @@ left unassigned, preventing low-confidence guesses from being applied.Defaults to 0.6.+#### [`PAPERLESS_MATCH_REGEX_TIMEOUT_SECONDS=<float>`](#PAPERLESS_MATCH_REGEX_TIMEOUT_SECONDS) {#PAPERLESS_MATCH_REGEX_TIMEOUT_SECONDS}++: Sets the timeout, in seconds, for regular expression matching. Increase this+value if date parsing or user-defined matching rules time out when processing+long documents, especially on slower hardware.++ Defaults to 0.1 seconds.+#### [`PAPERLESS_DATE_PARSER_LANGUAGES=<lang>`](#PAPERLESS_DATE_PARSER_LANGUAGES) {#PAPERLESS_DATE_PARSER_LANGUAGES}: Specifies which language Paperless should use when parsing dates from documents.diff --git a/src/documents/tests/test_regex.py b/src/documents/tests/test_regex.pyindex 7085199d1..d3aa04be5 100644--- a/src/documents/tests/test_regex.py+++ b/src/documents/tests/test_regex.py@@ -1,5 +1,6 @@import pytestimport regex+from django.conf import settingsfrom pytest_mock import MockerFixturefrom documents.regex import safe_regex_finditer@@ -9,6 +10,12 @@ from documents.regex import safe_regex_subfrom documents.regex import validate_regex_pattern+def test_regex_timeout_uses_configured_setting() -> None:+ from documents.regex import REGEX_TIMEOUT_SECONDS++ assert REGEX_TIMEOUT_SECONDS == settings.MATCH_REGEX_TIMEOUT_SECONDS++class TestValidateRegexPattern:def test_valid_pattern(self) -> None:validate_regex_pattern(r"\d+")diff --git a/src/paperless/settings/__init__.py b/src/paperless/settings/__init__.pyindex c64dd811d..2fc845742 100644--- a/src/paperless/settings/__init__.py+++ b/src/paperless/settings/__init__.py@@ -102,6 +102,10 @@ CLASSIFIER_MATCH_THRESHOLD: Final[float] = get_float_from_env("PAPERLESS_CLASSIFIER_MATCH_THRESHOLD",0.6,)+MATCH_REGEX_TIMEOUT_SECONDS: Final[float] = get_float_from_env(+ "PAPERLESS_MATCH_REGEX_TIMEOUT_SECONDS",+ 0.1,+)LLM_INDEX_DIR = DATA_DIR / "llm_index"LLM_INDEX_LOCK = LLM_INDEX_DIR / "index.lock"# Cross-process read/write lock guarding the LLM index compaction/migration