move ensure auto vacuum full when init database or change to full when already exists
This commit is contained in:
@@ -31,13 +31,16 @@ class GameplayDatabase:
|
|||||||
connection.execute(f"PRAGMA busy_timeout = {self.busy_timeout_ms}")
|
connection.execute(f"PRAGMA busy_timeout = {self.busy_timeout_ms}")
|
||||||
return connection
|
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:
|
def _initialize_database(self) -> None:
|
||||||
Path(self.db_path).parent.mkdir(parents=True, exist_ok=True)
|
Path(self.db_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
with self._connect() as connection:
|
with self._connect() as connection:
|
||||||
current_vacuum = connection.execute("PRAGMA auto_vacuum").fetchone()[0]
|
self._ensure_auto_vacuum_full(connection)
|
||||||
if current_vacuum != 1:
|
|
||||||
connection.execute("PRAGMA auto_vacuum = FULL")
|
|
||||||
connection.execute("VACUUM")
|
|
||||||
connection.executescript("""
|
connection.executescript("""
|
||||||
CREATE TABLE IF NOT EXISTS games (
|
CREATE TABLE IF NOT EXISTS games (
|
||||||
game_id TEXT PRIMARY KEY,
|
game_id TEXT PRIMARY KEY,
|
||||||
|
|||||||
Reference in New Issue
Block a user