From 2881868e7a61cbe4bc8d7db43cfa4fabb7eb996c Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 28 Oct 2023 10:27:15 +0100 Subject: [PATCH] refactor: Move precache db setting to prefs --- lang/en.json | 2 +- src/back/index.ts | 2 +- src/renderer/components/pages/ConfigPage.tsx | 7 ++----- src/shared/config/util.ts | 2 -- src/shared/preferences/util.ts | 2 ++ typings/flashpoint-launcher.d.ts | 4 ++-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lang/en.json b/lang/en.json index eabc39861..312978928 100644 --- a/lang/en.json +++ b/lang/en.json @@ -42,7 +42,7 @@ "auto": "Auto ({0})", "none": "None", "precacheDatabase": "Precache Database", - "precacheDatabaseDesc": "Caches some database tables to memory on boot. Improves responsiveness on slower drives at the expense of additional memory usage and boot time. Requires Save & Restart to apply changes.", + "precacheDatabaseDesc": "Caches some database tables to memory on boot. Improves responsiveness on slower drives at the expense of additional memory usage and boot time. Requires launcher restart to apply change.", "contentFiltersHeader": "Content Filters", "flashpointHeader": "Flashpoint", "flashpointPath": "Flashpoint Path", diff --git a/src/back/index.ts b/src/back/index.ts index b814e3700..4f097aeb0 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -754,7 +754,7 @@ async function initialize() { // TypeORM forces on but breaks Playlist Game links to unimported games await AppDataSource.query('PRAGMA foreign_keys=off;'); // Forcefully precache the tables into memory - if (state.config.precacheDatabase) { + if (state.preferences.precacheDatabase) { const dbSize = await fs.promises.stat(databasePath).then((stats) => stats.size); const start = performance.now(); await AppDataSource.query(`PRAGMA cache_size=${dbSize + 20000};`); diff --git a/src/renderer/components/pages/ConfigPage.tsx b/src/renderer/components/pages/ConfigPage.tsx index bff25b404..39e0df581 100644 --- a/src/renderer/components/pages/ConfigPage.tsx +++ b/src/renderer/components/pages/ConfigPage.tsx @@ -68,7 +68,6 @@ type ConfigPageState = { flashpointPath: string; /** If the "use custom title bar" checkbox is checked. */ useCustomTitlebar: boolean; - precacheDatabase: boolean; /** Currently editable Tag Filter Group */ editingTagFilterGroupIdx?: number; editingTagFilterGroup?: TagFilterGroup; @@ -95,7 +94,6 @@ export class ConfigPage extends React.Component @@ -796,7 +794,7 @@ export class ConfigPage extends React.Component { - this.setState({ precacheDatabase: isChecked }); + updatePreferencesData({ precacheDatabase: isChecked }); }; onSearchLimitChange = (event: React.ChangeEvent): void => { @@ -1072,7 +1070,6 @@ export class ConfigPage extends React.Component { window.Shared.restart(); }); }; diff --git a/src/shared/config/util.ts b/src/shared/config/util.ts index a4f88f279..86fcca0a6 100644 --- a/src/shared/config/util.ts +++ b/src/shared/config/util.ts @@ -23,7 +23,6 @@ const configDataDefaultBase: Readonly = Object.freeze({ gotdUrl: 'https://download.unstable.life/gotd.json', gotdShowAll: false, middlewareOverridePath: 'Legacy/middleware_overrides/', - precacheDatabase: false, }); /** @@ -82,7 +81,6 @@ export function overwriteConfigData( parser.prop('gotdUrl', v => source.gotdUrl = str(v)); parser.prop('gotdShowAll', v => source.gotdShowAll = !!v); parser.prop('middlewareOverridePath', v => source.middlewareOverridePath = str(v)); - parser.prop('precacheDatabase', v => source.precacheDatabase = !!v); // Do some alterations source.flashpointPath = fixSlashes(source.flashpointPath); // (Clean path) // Return diff --git a/src/shared/preferences/util.ts b/src/shared/preferences/util.ts index 6f7c6eecf..0cf7b42b0 100644 --- a/src/shared/preferences/util.ts +++ b/src/shared/preferences/util.ts @@ -145,6 +145,7 @@ export const defaultPreferencesData: Readonly = Object.freez gameMetadataSources: [], enablePlaytimeTracking: true, enablePlaytimeTrackingExtreme: true, + precacheDatabase: false, }); /** @@ -217,6 +218,7 @@ export function overwritePreferenceData( parser.prop('curateServer', v => source.curateServer = str(v), true); parser.prop('enablePlaytimeTracking', v => source.enablePlaytimeTracking = !!v, true); parser.prop('enablePlaytimeTrackingExtreme', v => source.enablePlaytimeTrackingExtreme = !!v, true); + parser.prop('precacheDatabase', v => source.precacheDatabase = !!v, true); // Migrate onDemandBaseUrl from the older FP url if (source.onDemandBaseUrl == 'https://infinity.unstable.life/Flashpoint/Data/Images/') { diff --git a/typings/flashpoint-launcher.d.ts b/typings/flashpoint-launcher.d.ts index a4b7ef394..5e948d788 100644 --- a/typings/flashpoint-launcher.d.ts +++ b/typings/flashpoint-launcher.d.ts @@ -966,8 +966,6 @@ declare module 'flashpoint-launcher' { gotdShowAll: boolean; /** Middleware override path */ middlewareOverridePath: string; - /** Whether to precache the Games and Tags tables in memory when booting */ - precacheDatabase: boolean; }; export type TagFilterGroup = { @@ -1109,6 +1107,8 @@ declare module 'flashpoint-launcher' { enablePlaytimeTracking: boolean; /** Enable Playtime Tracking for Extreme games (last played, playtime, play count) */ enablePlaytimeTrackingExtreme: boolean; + /** Whether to precache the Games and Tags tables in memory when booting */ + precacheDatabase: boolean; }; type GameDataSource = {