From 9a85723ae4620abf65d06aca32565a35a38f1de8 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 5 May 2026 08:42:27 -1000 Subject: [PATCH] collections: pack semantic index deltas per batch --- TreeDB/collections/api.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/TreeDB/collections/api.go b/TreeDB/collections/api.go index 21e89398a4..de27e1a671 100644 --- a/TreeDB/collections/api.go +++ b/TreeDB/collections/api.go @@ -9233,6 +9233,21 @@ func buildIndexedSemanticUpdateRecords(collectionName string, runtimes []indexRu return nil } records := make([]indexedSemanticRecord, 0, len(updates)) + totalIndexDeltas := 0 + if len(runtimes) > 0 { + for _, update := range updates { + if !update.indexStateChanged { + continue + } + for runtimeIdx := range runtimes { + if preparedBatchUpdateIndexChanged(update, runtimeIdx) { + totalIndexDeltas++ + } + } + } + } + indexDeltas := make([]indexedSemanticIndexDelta, totalIndexDeltas) + indexDeltaPos := 0 for i, update := range updates { var documentID []byte if i < len(primaryEntries) && len(primaryEntries[i].key) > 0 { @@ -9247,6 +9262,7 @@ func buildIndexedSemanticUpdateRecords(collectionName string, runtimes []indexRu documentID: documentID, } if update.indexStateChanged && len(runtimes) > 0 { + indexDeltaStart := indexDeltaPos for runtimeIdx, runtime := range runtimes { if !preparedBatchUpdateIndexChanged(update, runtimeIdx) { continue @@ -9254,14 +9270,18 @@ func buildIndexedSemanticUpdateRecords(collectionName string, runtimes []indexRu if runtime.def.unique { record.fallback = indexedSemanticFallbackRawOnly } - record.indexDeltas = append(record.indexDeltas, indexedSemanticIndexDelta{ + indexDeltas[indexDeltaPos] = indexedSemanticIndexDelta{ indexName: runtime.def.name, rootName: runtimeSecondaryRootName(collectionName, runtime), runtimeIdx: runtimeIdx, unique: runtime.def.unique, oldValues: cloneIndexedSemanticValueSet(update.oldState.valuesAt(runtimeIdx)), newValues: cloneIndexedSemanticValueSet(update.newState.valuesAt(runtimeIdx)), - }) + } + indexDeltaPos++ + } + if indexDeltaPos > indexDeltaStart { + record.indexDeltas = indexDeltas[indexDeltaStart:indexDeltaPos:indexDeltaPos] } } records = append(records, record)