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

Method indexBatchData

cmd/workers.go:228–258  ·  view source on GitHub ↗

indexBatchData indexes a batch of items into TypeSense 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, t *asynq.Task)

Source from the content-addressed store, hash-verified

226// It first indexes all dependencies (e.g., balances), then indexes the primary item (e.g., transaction).
227// This ensures referential integrity in the search index.
228func (b *ledgerforgeInstance) indexBatchData(ctx context.Context, t *asynq.Task) error {
229 if b.cnf.TypeSense.Dns == "" {
230 return nil
231 }
232
233 var batch search.IndexBatch
234
235 // Unmarshal the batch data from the task payload.
236 if err := json.Unmarshal(t.Payload(), &batch); err != nil {
237 logrus.Error(err)
238 return err
239 }
240
241 // Initialize a new TypeSense client and ensure collections exist.
242 newSearch := search.NewTypesenseClient(b.cnf.TypeSenseKey, []string{b.cnf.TypeSense.Dns})
243 err := newSearch.EnsureCollectionsExist(ctx)
244 if err != nil {
245 logrus.Errorf("Failed to ensure collections exist: %v", err)
246 return err
247 }
248
249 // Handle the batch notification - indexes dependencies first, then primary.
250 err = newSearch.HandleBatchNotification(ctx, &batch)
251 if err != nil {
252 logrus.Errorf("Error indexing batch %s: %v", batch.ID, err)
253 return err
254 }
255
256 logrus.Errorf(" [*] Batch indexed: %s (deps: %d)", batch.ID, len(batch.Dependencies))
257 return nil
258}
259
260// processInflightExpiry handles the expiry of inflight transactions.
261// It voids the transaction by its ID and logs the action.

Callers

nothing calls this directly

Calls 4

NewTypesenseClientFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected