From 6c282ac77f13800862b0c540e578dca0dfb88855 Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Tue, 26 May 2026 12:43:38 -0400 Subject: [PATCH] Add index change hook for incremental updates --- backend/indexer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/indexer.py b/backend/indexer.py index 806d637..d2c4217 100644 --- a/backend/indexer.py +++ b/backend/indexer.py @@ -27,6 +27,19 @@ _async_index_lock: asyncio.Lock = None # initialized lazily # (e.g. the inverted index in search.py) can detect staleness. _index_generation: int = 0 +# Hook for incremental inverted index updates: called as (action, vault, path, file_info) +_on_index_change: callable = None + + +def set_index_change_hook(hook): + """Register a callback for incremental inverted index updates. + + The hook is called as ``hook(action, vault_name, path, file_info)`` + where ``action`` is ``'add'`` or ``'remove'``. + """ + global _on_index_change + _on_index_change = hook + # O(1) lookup table for wikilink resolution: {filename_lower: [{vault, path}, ...]} _file_lookup: Dict[str, List[Dict[str, str]]] = {}