perf(organizations): cache and instrument API responses

This commit is contained in:
2026-05-14 16:14:45 +02:00
parent 6d1ec2e55c
commit 5fdd23ecc0
13 changed files with 603 additions and 33 deletions

View File

@@ -171,6 +171,7 @@ MIDDLEWARE = [
"django.middleware.common.CommonMiddleware",
"apps.core.middleware.ApiCsrfExemptMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"apps.core.middleware.OrganizationApiMetricsMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
@@ -381,6 +382,10 @@ LOGGING = {
"format": "{levelname} {message}",
"style": "{",
},
"metrics": {
"format": "{message}",
"style": "{",
},
},
"handlers": {
"file": {
@@ -389,6 +394,14 @@ LOGGING = {
"filename": PROJECT_ROOT / "logs/django.log",
"formatter": "verbose",
},
"organizations_api_metrics_file": {
"level": "INFO",
"class": "logging.handlers.RotatingFileHandler",
"filename": PROJECT_ROOT / "logs/organizations_api_metrics.log",
"maxBytes": 20 * 1024 * 1024,
"backupCount": 5,
"formatter": "metrics",
},
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
@@ -405,6 +418,11 @@ LOGGING = {
"level": "INFO",
"propagate": False,
},
"organizations.api.metrics": {
"handlers": ["organizations_api_metrics_file"],
"level": "INFO",
"propagate": False,
},
},
}

View File

@@ -95,6 +95,10 @@ LOGGING = {
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
"style": "{",
},
"metrics": {
"format": "{message}",
"style": "{",
},
},
"handlers": {
"console": {
@@ -102,6 +106,14 @@ LOGGING = {
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"organizations_api_metrics_file": {
"level": "INFO",
"class": "logging.handlers.RotatingFileHandler",
"filename": PROJECT_ROOT / "logs/organizations_api_metrics.log",
"maxBytes": 20 * 1024 * 1024,
"backupCount": 5,
"formatter": "metrics",
},
},
"root": {
"handlers": ["console"],
@@ -113,5 +125,10 @@ LOGGING = {
"level": "INFO",
"propagate": False,
},
"organizations.api.metrics": {
"handlers": ["organizations_api_metrics_file"],
"level": "INFO",
"propagate": False,
},
},
}