feat: Add analytics, incident, and alert models and APIs, along with user permissions and bulk profile lookups.

This commit is contained in:
pacnpal
2026-01-07 11:07:36 -05:00
parent 4da7e52fb0
commit 3ec5a4857d
46 changed files with 4012 additions and 199 deletions

View File

@@ -48,8 +48,18 @@ DATABASES = {
# CONN_MAX_AGE: How long to keep connections open (in seconds)
# 0 = Close after each request (default Django behavior)
# None = Unlimited reuse (not recommended)
# 600 = 10 minutes (good balance for most applications)
CONN_MAX_AGE = config("DATABASE_CONN_MAX_AGE", default=600, cast=int)
# 60 = 1 minute (good for development to prevent connection accumulation)
# 600 = 10 minutes (good for production)
# Check if we're in debug mode (imported from base settings)
DEBUG = config("DEBUG", default=False, cast=bool)
# Use shorter connection lifetime in development to prevent accumulation
CONN_MAX_AGE = config(
"DATABASE_CONN_MAX_AGE",
default=60 if DEBUG else 600,
cast=int
)
# Apply CONN_MAX_AGE to the default database
DATABASES["default"]["CONN_MAX_AGE"] = CONN_MAX_AGE
@@ -59,12 +69,21 @@ DATABASES["default"]["CONN_MAX_AGE"] = CONN_MAX_AGE
# =============================================================================
# These settings are passed to psycopg2 when creating new connections
# Shorter timeouts in development to fail fast
connect_timeout = config("DATABASE_CONNECT_TIMEOUT", default=5 if DEBUG else 10, cast=int)
statement_timeout = config("DATABASE_STATEMENT_TIMEOUT", default=30000, cast=int)
# Idle in transaction timeout: close connections that sit idle in a transaction
# This prevents connection leaks from unclosed transactions
idle_in_transaction_timeout = config("DATABASE_IDLE_IN_TRANSACTION_TIMEOUT", default=60000, cast=int)
DATABASE_OPTIONS = {
# Connection timeout in seconds
"connect_timeout": config("DATABASE_CONNECT_TIMEOUT", default=10, cast=int),
# Query timeout in milliseconds (30 seconds default)
# This prevents runaway queries from blocking the database
"options": f"-c statement_timeout={config('DATABASE_STATEMENT_TIMEOUT', default=30000, cast=int)}",
"connect_timeout": connect_timeout,
# PostgreSQL server-side options
"options": (
f"-c statement_timeout={statement_timeout} "
f"-c idle_in_transaction_session_timeout={idle_in_transaction_timeout}"
),
}
# Apply options to PostgreSQL databases
@@ -72,6 +91,7 @@ if "postgis" in DATABASE_URL or "postgresql" in DATABASE_URL:
DATABASES["default"].setdefault("OPTIONS", {})
DATABASES["default"]["OPTIONS"].update(DATABASE_OPTIONS)
# =============================================================================
# GeoDjango Settings
# =============================================================================