diff --git a/changedetectionio/api/__init__.py b/changedetectionio/api/__init__.py index 4004e0196..cb607c8fc 100644 --- a/changedetectionio/api/__init__.py +++ b/changedetectionio/api/__init__.py @@ -1,10 +1,7 @@ import copy -import yaml import functools from flask import request, abort from loguru import logger -from openapi_core import OpenAPI -from openapi_core.contrib.flask import FlaskOpenAPIRequest from . import api_schema from ..model import watch_base @@ -34,7 +31,11 @@ schema_delete_notification_urls['required'] = ['notification_urls'] @functools.cache def get_openapi_spec(): + """Lazy load OpenAPI spec and dependencies only when validation is needed.""" import os + import yaml # Lazy import - only loaded when API validation is actually used + from openapi_core import OpenAPI # Lazy import - saves ~10.7 MB on startup + spec_path = os.path.join(os.path.dirname(__file__), '../../docs/api-spec.yaml') with open(spec_path, 'r') as f: spec_dict = yaml.safe_load(f) @@ -49,6 +50,9 @@ def validate_openapi_request(operation_id): try: # Skip OpenAPI validation for GET requests since they don't have request bodies if request.method.upper() != 'GET': + # Lazy import - only loaded when actually validating a request + from openapi_core.contrib.flask import FlaskOpenAPIRequest + spec = get_openapi_spec() openapi_request = FlaskOpenAPIRequest(request) result = spec.unmarshal_request(openapi_request) diff --git a/changedetectionio/processors/magic.py b/changedetectionio/processors/magic.py index 7768ce084..a742b9f88 100644 --- a/changedetectionio/processors/magic.py +++ b/changedetectionio/processors/magic.py @@ -44,11 +44,8 @@ XML_CONTENT_TYPES = [ HTML_PATTERNS = ['