Chore: Set various optimizations to database connection
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 19 Jan 2025 20:37:32 +0000 (21:37 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 19 Jan 2025 20:37:32 +0000 (21:37 +0100)
Prefer performance over integrity

music_assistant/helpers/database.py

index 9e0e37e12a813da3f9d0f8371497dc59fac65939..8d1cf2b169b6f39ac7d699fb015e408f6235b3ba 100644 (file)
@@ -80,8 +80,15 @@ class DatabaseConnection:
         """Perform async initialization."""
         self._db = await aiosqlite.connect(self.db_path)
         self._db.row_factory = aiosqlite.Row
+        # setup some default settings for more performance
         await self.execute("PRAGMA analysis_limit=10000;")
-        await self.execute("PRAGMA optimize;")
+        await self.execute("PRAGMA locking_mode=exclusive;")
+        await self.execute("PRAGMA journal_mode=WAL;")
+        await self.execute("PRAGMA journal_size_limit = 6144000;")
+        await self.execute("PRAGMA synchronous=normal;")
+        await self.execute("PRAGMA temp_store=memory;")
+        await self.execute("PRAGMA mmap_size = 30000000000;")
+        await self.execute("PRAGMA cache_size = -64000;")
         await self.commit()
 
     async def close(self) -> None: