From 6f255c9ff80885744b77ffeb5fb5ccc228d2d9ef Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 16 Aug 2024 11:53:34 +0200 Subject: [PATCH] Make Sqlite3 PRAGMAs customizable from settings --- CHANGELOG.md | 16 +++++++++------- evennia/server/service.py | 15 ++++++--------- evennia/settings_default.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533de8ca14..d4374b6f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,16 @@ ## Main branch -Feat: Support `scripts key:typeclass` form to create global scripts -with dynamic keys (rather than just relying on typeclass' key). Support -searching using the same syntax (Griatch) -[Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch) -[Fix][issue3590]: Make `examine` command properly show `strattr` type +- Feat: Support `scripts key:typeclass` to create global scripts +with dynamic keys (rather than just relying on typeclass' key) (Griatch) +- [Feat][pull3595]: Tweak Sqlite3 PRAGMAs for better performance (0xDEADFED5) +- Feat: Make Sqlite3 PRAGMAs configurable via settings (Griatch) +- [Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch) +- [Fix][issue3590]: Make `examine` command properly show `strattr` type Attribute values (Griatch) -[Fix][issue3519]: `GLOBAL_SCRIPTS` container didn't list global scripts not +- [Fix][issue3519]: `GLOBAL_SCRIPTS` container didn't list global scripts not defined explicitly to be restarted/recrated in settings.py (Griatch) -Fix: Passing an already instantiated Script to `obj.scripts.add` (`ScriptHandler.add`) +- Fix: Passing an already instantiated Script to `obj.scripts.add` (`ScriptHandler.add`) did not add it to the handler's object (Griatch) [Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch) @@ -18,6 +19,7 @@ did not add it to the handler's object (Griatch) [issue3590]: https://github.com/evennia/evennia/issues/3590 [issue3556]: https://github.com/evennia/evennia/issues/3556 [issue3519]: https://github.com/evennia/evennia/issues/3519 +[pull3595]: https://github.com/evennia/evennia/pull/3595 ## Evennia 4.3.0 diff --git a/evennia/server/service.py b/evennia/server/service.py index 1fbf14d152..80eba12bb0 100644 --- a/evennia/server/service.py +++ b/evennia/server/service.py @@ -8,20 +8,19 @@ import time import traceback import django +import evennia from django.conf import settings from django.db import connection from django.db.utils import OperationalError from django.utils.translation import gettext as _ +from evennia.utils import logger +from evennia.utils.utils import get_evennia_version, make_iter, mod_import from twisted.application import internet from twisted.application.service import MultiService from twisted.internet import defer, reactor from twisted.internet.defer import Deferred from twisted.internet.task import LoopingCall -import evennia -from evennia.utils import logger -from evennia.utils.utils import get_evennia_version, make_iter, mod_import - _SA = object.__setattr__ @@ -282,12 +281,10 @@ class EvenniaServerService(MultiService): and settings.DATABASES.get("default", {}).get("ENGINE", None) == "django.db.backends.sqlite3" ): + # sqlite3 database pragmas (directives) cursor = connection.cursor() - cursor.execute("PRAGMA cache_size=10000") - cursor.execute("PRAGMA synchronous=1") - cursor.execute("PRAGMA count_changes=OFF") - cursor.execute("PRAGMA temp_store=2") - cursor.execute("PRAGMA journal_mode=WAL") + for pragma in settings.SQLITE3_PRAGMAS: + cursor.execute(pragma) def update_defaults(self): """ diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 50a27ce1b5..ccd3bcccc2 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -300,6 +300,16 @@ DATABASES = { "PORT": "", } } +# PRAGMA (directives) for the default Sqlite3 database operations. This can be used to tweak +# performance for your setup. Don't change this unless you know what # you are doing. +SQLITE3_PRAGMAS = ( + "PRAGMA cache_size=10000", + "PRAGMA synchronous=1", + "PRAGMA count_changes=OFF", + "PRAGMA temp_store=2", + "PRAGMA journal_mode=WAL", +) + # How long the django-database connection should be kept open, in seconds. # If you get errors about the database having gone away after long idle # periods, shorten this value (e.g. MySQL defaults to a timeout of 8 hrs)