feat(obsidian): add FMG ID index for instant note lookups

Problem: Every time you click on a burg/marker, it had to scan through
all 13,496 vault files looking for a matching fmg-id. This was extremely
slow and made the feature unusable for large vaults.

Solution: Implement a smart index that maps fmg-id to file paths.

How it works:
- Index stored in memory (fmgIdIndex object)
- Persisted to localStorage (survives page reloads)
- Loaded on init, saved on changes
- When looking up by fmg-id:
  1. Check index first (instant!)
  2. If found, verify file still exists and ID matches
  3. If not in index, search vault and add to index
- Automatically updates when notes are created/saved through FMG
- Handles stale entries (file deleted/modified)

Performance improvement:
- Before: O(n) - scan all 13k files (very slow)
- After: O(1) - instant lookup from index
- First click on burg: May need to search (builds index)
- Second click on same burg: Instant! Opens note directly

This makes the Obsidian integration actually usable. Create a note once
for a burg, and every time you click that burg again, it opens instantly.
This commit is contained in:
Claude 2025-11-14 05:29:36 +00:00
parent a22b40e7ca
commit f575631e30
No known key found for this signature in database
2 changed files with 98 additions and 2 deletions

View file

@ -216,6 +216,13 @@ async function promptCreateNewNote(elementId, elementType, coordinates) {
const {frontmatter} = ObsidianBridge.parseFrontmatter(template);
// Add to FMG ID index for instant future lookups
const fmgId = frontmatter["fmg-id"] || frontmatter.fmgId;
if (fmgId) {
ObsidianBridge.addToFmgIdIndex(fmgId, notePath);
INFO && console.log(`New note added to index: ${fmgId}${notePath}`);
}
resolve({
path: notePath,
name,
@ -590,6 +597,17 @@ async function saveObsidianNote() {
try {
await ObsidianBridge.updateNote(path, content);
// Update the FMG ID index if this note has an fmg-id
if (elementId) {
const {frontmatter} = ObsidianBridge.parseFrontmatter(content);
const fmgId = frontmatter["fmg-id"] || frontmatter.fmgId;
if (fmgId) {
// Add to index using internal method
ObsidianBridge.addToFmgIdIndex(fmgId, path);
}
}
showMarkdownEditor.originalContent = content;
// Update the editor to show the new frontmatter
byId("obsidianMarkdownEditor").value = content;