Skip to content

Commit

Permalink
feat(db): reuse connections for 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Sep 15, 2024
1 parent ba1ebb2 commit 002aa1d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
6 changes: 5 additions & 1 deletion fiesta/fiesta/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class Production(
@property
def DATABASES(self):
return {
"default": dj_database_url.parse(self.DATABASE_URL),
"default": dj_database_url.parse(
self.DATABASE_URL,
conn_max_age=self.DATABASE_CONN_MAX_AGE,
conn_health_checks=self.DATABASE_CONN_HEALTH_CHECKS,
),
"wiki": DatabaseConfigMixin.DATABASES["wiki"],
}

Expand Down
53 changes: 31 additions & 22 deletions fiesta/fiesta/settings/db.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
from __future__ import annotations

from configurations.values import Value


class DatabaseConfigMixin:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": "db",
"USER": "fiesta",
"NAME": "fiesta",
"PASSWORD": "fiesta",
},
"legacydb": {
"ENGINE": "django.db.backends.mysql",
"HOST": "legacydb",
"NAME": "fiesta",
# TODO: access to legacy db by standard user
"USER": "root",
"PASSWORD": "root",
},
"wiki": {
"ENGINE": "django.db.backends.sqlite3",
# TODO: pass from ENV
"NAME": "/usr/src/wiki/db/wiki.sqlite3",
},
}
DATABASE_CONN_MAX_AGE = Value(default=5 * 60)
DATABASE_CONN_HEALTH_CHECKS = Value(default=True)

@property
def DATABASES(self):
return {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": "db",
"USER": "fiesta",
"NAME": "fiesta",
"PASSWORD": "fiesta",
"CONN_MAX_AGE": self.DATABASE_CONN_MAX_AGE,
"CONN_HEALTH_CHECKS": self.DATABASE_CONN_HEALTH_CHECKS,
},
"legacydb": {
"ENGINE": "django.db.backends.mysql",
"HOST": "legacydb",
"NAME": "fiesta",
# TODO: access to legacy db by standard user
"USER": "root",
"PASSWORD": "root",
},
"wiki": {
"ENGINE": "django.db.backends.sqlite3",
# TODO: pass from ENV
"NAME": "/usr/src/wiki/db/wiki.sqlite3",
},
}

0 comments on commit 002aa1d

Please sign in to comment.