From 2fd3dcc1a86a85bab5840d01cba4da84d667b871 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Fri, 14 Mar 2025 07:25:00 +1300 Subject: [PATCH] PRAGMA optimize --- Dotnet/SQLiteLegacy.cs | 2 +- src/app.js | 1 + src/classes/updateLoop.js | 7 ++++++- src/repository/database.js | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Dotnet/SQLiteLegacy.cs b/Dotnet/SQLiteLegacy.cs index 9a2c293d..08762a9b 100644 --- a/Dotnet/SQLiteLegacy.cs +++ b/Dotnet/SQLiteLegacy.cs @@ -34,7 +34,7 @@ namespace VRCX if (!string.IsNullOrEmpty(jsonDataSource)) dataSource = jsonDataSource; - m_Connection = new SQLiteConnection($"Data Source=\"{dataSource}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000;PRAGMA journal_mode=WAL;", true); + m_Connection = new SQLiteConnection($"Data Source=\"{dataSource}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000;PRAGMA journal_mode=WAL;PRAGMA optimize=0x10002;", true); m_Connection.Open(); } diff --git a/src/app.js b/src/app.js index a708afdb..f1182039 100644 --- a/src/app.js +++ b/src/app.js @@ -18132,6 +18132,7 @@ console.log(`isLinux: ${LINUX}`); await database.fixBrokenGameLogDisplayNames(); // fix gameLog display names "DisplayName (userId)" await database.upgradeDatabaseVersion(); // update database version await database.vacuum(); // succ + await database.optimize(); await configRepository.setInt( 'VRCX_databaseVersion', databaseVersion diff --git a/src/classes/updateLoop.js b/src/classes/updateLoop.js index 4c147912..1e48a7be 100644 --- a/src/classes/updateLoop.js +++ b/src/classes/updateLoop.js @@ -24,7 +24,8 @@ export default class extends baseClass { nextDiscordUpdate: 0, nextAutoStateChange: 0, nextGetLogCheck: 0, - nextGameRunningCheck: 0 + nextGameRunningCheck: 0, + nextDatabaseOptimize: 3600 }; _methods = { @@ -105,6 +106,10 @@ export default class extends baseClass { AppApi.CheckGameRunning(); } } + if (--this.nextDatabaseOptimize <= 0) { + this.nextDatabaseOptimize = 86400; // 1 day + database.optimize(); + } } } catch (err) { API.isRefreshFriendsLoading = false; diff --git a/src/repository/database.js b/src/repository/database.js index 0d610bb6..b987d485 100644 --- a/src/repository/database.js +++ b/src/repository/database.js @@ -2754,6 +2754,10 @@ class Database { await sqliteService.executeNonQuery('VACUUM'); } + async optimize() { + await sqliteService.executeNonQuery('PRAGMA optimize'); + } + async getInstanceJoinHistory() { var oneWeekAgo = new Date(Date.now() - 604800000).toJSON(); var instances = new Map();