feat(FN-1336): add write-through cache to GlobalSettingsStore

- Add in-memory cache to GlobalSettingsStore for fast settings reads
- Add getSettingsFast() to TaskStore that uses the cached settings
- Update GET /settings route to use getSettingsFast() for faster responses
- Add invalidateCache() method for testing and external process scenarios
- Document write-through cache pattern in .fusion/memory.md
This commit is contained in:
gsxdsm
2026-04-10 03:03:51 -07:00
parent f246fe4896
commit 3cb59159e5
7 changed files with 168 additions and 10 deletions

View File

@@ -605,6 +605,31 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
};
}
/**
* Fast-path settings read that skips the expensive workflow steps query.
*
* This method reads only the `settings` column from the SQLite config row
* (avoiding `readConfig()` which always calls `listWorkflowSteps()`), and
* uses the cached global settings from `GlobalSettingsStore`. Use this for
* read-heavy paths like the settings page that don't need workflow steps.
*
* Note: Do NOT use this method when you need workflow steps — use `getSettings()` instead.
*/
async getSettingsFast(): Promise<Settings> {
const [globalSettings, row] = await Promise.all([
this.globalSettingsStore.getSettings(),
this.db.prepare("SELECT settings FROM config WHERE id = 1").get() as { settings?: string } | undefined,
]);
const projectSettings = row?.settings ? fromJson<Settings>(row.settings) : undefined;
return {
...DEFAULT_SETTINGS,
...globalSettings,
...projectSettings,
};
}
/**
* Get settings separated by scope. Returns both the global and
* project-level settings independently (useful for the UI to show