Enable Write-Ahead Logging (WAL) for SQLite to improve performance when using it.
This commit is contained in:
parent
d44b31f024
commit
1a5f1d5e81
3 changed files with 21 additions and 1 deletions
|
|
@ -129,6 +129,9 @@ DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
||||||
|
"OPTIONS": {
|
||||||
|
"timeout": 10,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,25 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db.backends.signals import connection_created
|
||||||
|
|
||||||
|
|
||||||
class PhotologueConfig(AppConfig):
|
class PhotologueConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.AutoField"
|
default_auto_field = "django.db.models.AutoField"
|
||||||
name = "photologue"
|
name = "photologue"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from django.db import connection
|
||||||
|
|
||||||
|
def enable_sqlite_wal(sender, connection, **kwargs):
|
||||||
|
if connection.vendor == "sqlite":
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("PRAGMA journal_mode=WAL;")
|
||||||
|
cursor.execute("PRAGMA synchronous=OFF;")
|
||||||
|
cursor.execute("PRAGMA journal_size_limit=67108864;")
|
||||||
|
cursor.execute("PRAGMA wal_autocheckpoint=1000;")
|
||||||
|
cursor.execute("PRAGMA cache_size=-65536;")
|
||||||
|
cursor.execute("PRAGMA temp_store=MEMORY;")
|
||||||
|
cursor.execute("PRAGMA mmap_size=268435456;")
|
||||||
|
|
||||||
|
connection_created.connect(enable_sqlite_wal)
|
||||||
|
|
|
||||||
|
|
@ -486,7 +486,7 @@ class ImageModel(models.Model):
|
||||||
self._old_image.storage.delete(
|
self._old_image.storage.delete(
|
||||||
self._old_image.name
|
self._old_image.name
|
||||||
) # Delete (old) base image.
|
) # Delete (old) base image.
|
||||||
if self.date_taken is None or image_has_changed:
|
if (self.date_taken is None or image_has_changed) and self.image:
|
||||||
# Attempt to get the date the photo was taken from the EXIF data.
|
# Attempt to get the date the photo was taken from the EXIF data.
|
||||||
try:
|
try:
|
||||||
exif_date = self.exif(self.image.file).get(
|
exif_date = self.exif(self.image.file).get(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue