MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / HandleBatchNotification

Method HandleBatchNotification

internal/search/search.go:252–279  ·  view source on GitHub ↗

HandleBatchNotification processes a batch of items and indexes them in dependency order. It first indexes all dependencies (e.g., balances), then indexes the primary item (e.g., transaction). This ensures referential integrity in the search index.

(ctx context.Context, batch *IndexBatch)

Source from the content-addressed store, hash-verified

250// It first indexes all dependencies (e.g., balances), then indexes the primary item (e.g., transaction).
251// This ensures referential integrity in the search index.
252func (t *TypesenseClient) HandleBatchNotification(ctx context.Context, batch *IndexBatch) error {
253 // Deduplicate dependencies to avoid redundant indexing
254 batch.Deduplicate()
255
256 // Step 1: Index all dependencies first (in order)
257 for _, dep := range batch.Dependencies {
258 data, err := toMap(dep.Data)
259 if err != nil {
260 return fmt.Errorf("failed to convert dependency %s/%s to map: %w", dep.Collection, dep.DocumentID, err)
261 }
262 if err := t.HandleNotification(ctx, dep.Collection, data); err != nil {
263 return fmt.Errorf("failed to index dependency %s/%s: %w", dep.Collection, dep.DocumentID, err)
264 }
265 }
266
267 // Step 2: Index primary entity after dependencies exist
268 if batch.Primary != nil {
269 data, err := toMap(batch.Primary.Data)
270 if err != nil {
271 return fmt.Errorf("failed to convert primary %s/%s to map: %w", batch.Primary.Collection, batch.Primary.DocumentID, err)
272 }
273 if err := t.HandleNotification(ctx, batch.Primary.Collection, data); err != nil {
274 return fmt.Errorf("failed to index primary %s/%s: %w", batch.Primary.Collection, batch.Primary.DocumentID, err)
275 }
276 }
277
278 return nil
279}
280
281// toMap converts an interface{} to map[string]interface{} via JSON marshaling.
282func toMap(data interface{}) (map[string]interface{}, error) {

Callers 1

indexBatchDataMethod · 0.95

Calls 3

HandleNotificationMethod · 0.95
toMapFunction · 0.85
DeduplicateMethod · 0.80

Tested by

no test coverage detected