move ensure auto vacuum full when init database or change to full when already exists

This commit is contained in:
2026-04-06 16:35:05 +02:00
parent fe999c11f4
commit 1a1bcd8ec3
+7 -4
View File
@@ -31,13 +31,16 @@ class GameplayDatabase:
connection.execute(f"PRAGMA busy_timeout = {self.busy_timeout_ms}")
return connection
def _ensure_auto_vacuum_full(self, connection:sqlite3.Connection) -> None:
current = connection.execute("PRAGMA auto_vacuum").fetchone()[0]
if current != 1:
connection.execute("PRAGMA auto_vacuum = FULL")
connection.execute("VACUUM")
def _initialize_database(self) -> None:
Path(self.db_path).parent.mkdir(parents=True, exist_ok=True)
with self._connect() as connection:
current_vacuum = connection.execute("PRAGMA auto_vacuum").fetchone()[0]
if current_vacuum != 1:
connection.execute("PRAGMA auto_vacuum = FULL")
connection.execute("VACUUM")
self._ensure_auto_vacuum_full(connection)
connection.executescript("""
CREATE TABLE IF NOT EXISTS games (
game_id TEXT PRIMARY KEY,