Coalesce index generation increments and add rebuild cooldown
This commit is contained in:
@@ -379,9 +379,14 @@ async def _on_vault_change(events: list):
|
||||
Processes each event (create/modify/delete/move) and updates the index
|
||||
incrementally, then broadcasts SSE notifications.
|
||||
"""
|
||||
import backend.indexer as idx
|
||||
updated_vaults = set()
|
||||
changes = []
|
||||
|
||||
# Temporarily suppress per-file generation increments to coalesce them
|
||||
# into a single increment at the end of the batch.
|
||||
old_gen = idx._index_generation
|
||||
|
||||
for event in events:
|
||||
vault_name = event["vault"]
|
||||
event_type = event["type"]
|
||||
@@ -410,6 +415,11 @@ async def _on_vault_change(events: list):
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing {event_type} event for {src}: {e}")
|
||||
|
||||
# Restore generation to only increment by 1 for the whole batch
|
||||
# (unless it was already incremented by other operations)
|
||||
if idx._index_generation > old_gen + 1:
|
||||
idx._index_generation = old_gen + 1
|
||||
|
||||
if changes:
|
||||
await sse_manager.broadcast("index_updated", {
|
||||
"vaults": list(updated_vaults),
|
||||
|
||||
Reference in New Issue
Block a user