Skip to content

Commit

Permalink
refactor: Move precache db setting to prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Oct 28, 2023
1 parent 9c666de commit 2881868
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/back/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};`);
Expand Down
7 changes: 2 additions & 5 deletions src/renderer/components/pages/ConfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -95,7 +94,6 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
useCustomTitlebar: configData.useCustomTitlebar,
editorOpen: false,
nukeInProgress: false,
precacheDatabase: configData.precacheDatabase,
};
}

Expand Down Expand Up @@ -206,7 +204,7 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
<ConfigBoxCheckbox
title={strings.precacheDatabase}
description={strings.precacheDatabaseDesc}
checked={this.state.precacheDatabase}
checked={this.props.preferencesData.precacheDatabase}
onToggle={this.onPrecacheDatabaseToggle} />
</div>
</div>
Expand Down Expand Up @@ -796,7 +794,7 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
};

onPrecacheDatabaseToggle = (isChecked: boolean): void => {
this.setState({ precacheDatabase: isChecked });
updatePreferencesData({ precacheDatabase: isChecked });
};

onSearchLimitChange = (event: React.ChangeEvent<HTMLSelectElement>): void => {
Expand Down Expand Up @@ -1072,7 +1070,6 @@ export class ConfigPage extends React.Component<ConfigPageProps, ConfigPageState
window.Shared.back.request(BackIn.UPDATE_CONFIG, {
flashpointPath: this.state.flashpointPath,
useCustomTitlebar: this.state.useCustomTitlebar,
precacheDatabase: this.state.precacheDatabase,
}).then(() => { window.Shared.restart(); });
};

Expand Down
2 changes: 0 additions & 2 deletions src/shared/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const configDataDefaultBase: Readonly<AppConfigData> = Object.freeze({
gotdUrl: 'https://download.unstable.life/gotd.json',
gotdShowAll: false,
middlewareOverridePath: 'Legacy/middleware_overrides/',
precacheDatabase: false,
});

/**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/shared/preferences/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const defaultPreferencesData: Readonly<AppPreferencesData> = Object.freez
gameMetadataSources: [],
enablePlaytimeTracking: true,
enablePlaytimeTrackingExtreme: true,
precacheDatabase: false,
});

/**
Expand Down Expand Up @@ -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/') {
Expand Down
4 changes: 2 additions & 2 deletions typings/flashpoint-launcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 2881868

Please sign in to comment.