Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Preload as much of the app as possible (#16241)
Patryk Zawadzki0f0d85b1dc46
diff --git a/saleor/asgi/__init__.py b/saleor/asgi/__init__.pyindex 44df76bfd7..98eeb93327 100644--- a/saleor/asgi/__init__.py+++ b/saleor/asgi/__init__.py@@ -14,9 +14,23 @@ from .cors_handler import cors_handlerfrom .gzip_compression import gzip_compressionfrom .health_check import health_check++def preload_app() -> None:+ """Import the app code to make sure that Django application is loaded.++ By default, Django does not import the application until the first request is processed.+ """+ from django.conf import settings+ from django.urls import get_resolver++ get_resolver(settings.ROOT_URLCONF).url_patterns++os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")application = get_asgi_application()application = health_check(application, "/health/") # type: ignore[arg-type] # Django's ASGI app is less strict than the spec # noqa: E501application = gzip_compression(application)application = cors_handler(application)++preload_app()