Add index change hook for incremental updates

This commit is contained in:
Bruno Charest 2026-05-26 12:43:38 -04:00
parent 775722f5d4
commit 6c282ac77f

View File

@ -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]]] = {}