mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
feat(obsidian): pre-warm vault cache on startup for instant browsing
Problem: The first time you browse notes, it has to scan all 13,496 files, which is very slow. This makes the initial user experience poor. Solution: Pre-warm the vault file cache in the background: 1. When Obsidian connection is tested (first-time setup) 2. When FMG loads and Obsidian is already enabled (page reload) Implementation: - Add prewarmCache() function that scans vault in background - Call it from testConnection() (don't await - runs async) - Call it from init() if config.enabled is true - Scan happens silently in the background - By the time user clicks Browse, cache is already loaded Benefits: - First browse is instant (cache already loaded) - Works on every page reload - Non-blocking (doesn't slow down FMG startup) - Silent/automatic (no user interaction needed) User experience: - First time: Test connection → cache warms in background → browse is instant - Subsequent loads: Page loads → cache warms → browse is instant - Cache lasts 5 minutes, so multiple browses within that window are all instant EOF )
This commit is contained in:
parent
4e8b9e9b0d
commit
69e69abb85
1 changed files with 22 additions and 0 deletions
|
|
@ -46,6 +46,12 @@ const ObsidianBridge = (() => {
|
||||||
fmgIdIndex = {};
|
fmgIdIndex = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-warm cache if Obsidian is already enabled
|
||||||
|
if (config.enabled) {
|
||||||
|
INFO && console.log("Obsidian enabled, pre-warming cache...");
|
||||||
|
prewarmCache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save configuration
|
// Save configuration
|
||||||
|
|
@ -74,6 +80,10 @@ const ObsidianBridge = (() => {
|
||||||
INFO && console.log("Obsidian connection successful:", data);
|
INFO && console.log("Obsidian connection successful:", data);
|
||||||
config.enabled = true;
|
config.enabled = true;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
// Pre-warm the cache in the background (don't await)
|
||||||
|
prewarmCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ERROR && console.error("Obsidian connection failed:", error);
|
ERROR && console.error("Obsidian connection failed:", error);
|
||||||
|
|
@ -83,6 +93,18 @@ const ObsidianBridge = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-warm the vault files cache in the background
|
||||||
|
async function prewarmCache() {
|
||||||
|
try {
|
||||||
|
INFO && console.log("Pre-warming vault file cache...");
|
||||||
|
await getVaultFiles();
|
||||||
|
INFO && console.log("Vault file cache pre-warmed successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
WARN && console.warn("Failed to pre-warm cache:", error);
|
||||||
|
// Don't throw - this is just optimization
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Recursively scan a directory and all subdirectories for .md files
|
// Recursively scan a directory and all subdirectories for .md files
|
||||||
async function scanDirectory(path = "") {
|
async function scanDirectory(path = "") {
|
||||||
const response = await fetch(`${config.apiUrl}/vault/${encodeURIComponent(path)}`, {
|
const response = await fetch(`${config.apiUrl}/vault/${encodeURIComponent(path)}`, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue