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

Method indexData

cmd/workers.go:190–223  ·  view source on GitHub ↗

indexData indexes data into TypeSense for searchability. It fetches the collection name and payload from the task, ensures the collections exist, and sends the payload to the appropriate TypeSense collection for indexing.

(ctx context.Context, t *asynq.Task)

Source from the content-addressed store, hash-verified

188// It fetches the collection name and payload from the task, ensures the collections exist,
189// and sends the payload to the appropriate TypeSense collection for indexing.
190func (b *ledgerforgeInstance) indexData(ctx context.Context, t *asynq.Task) error {
191 if b.cnf.TypeSense.Dns == "" {
192 return nil
193 }
194
195 var data indexData
196
197 // Unmarshal the indexing data from the task payload.
198 if err := json.Unmarshal(t.Payload(), &data); err != nil {
199 logrus.Error(err)
200 return err
201 }
202
203 collection := data.Collection
204 payload := data.Payload
205
206 // Initialize a new TypeSense client and ensure collections exist.
207 newSearch := search.NewTypesenseClient(b.cnf.TypeSenseKey, []string{b.cnf.TypeSense.Dns})
208 err := newSearch.EnsureCollectionsExist(ctx)
209 if err != nil {
210 logrus.Errorf("Failed to ensure collections exist: %v", err)
211 return err
212 }
213
214 // Handle the notification and send the payload to the collection for indexing.
215 err = newSearch.HandleNotification(ctx, collection, payload)
216 if err != nil {
217 logrus.Error("Error indexing data", err)
218 return err
219 }
220
221 logrus.Error(" [*] Data indexed", collection)
222 return nil
223}
224
225// indexBatchData indexes a batch of items into TypeSense in dependency order.
226// It first indexes all dependencies (e.g., balances), then indexes the primary item (e.g., transaction).

Callers

nothing calls this directly

Calls 4

HandleNotificationMethod · 0.95
NewTypesenseClientFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected