Skip to content

Commit

Permalink
Add goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Mar 26, 2024
1 parent f50175a commit a8d025b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/state/indexer/indexer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,21 @@ func (is *Service) publish(msg pubsub.Message) error {
}

if curr.Size() != 0 {
start := time.Now()
err := sink.IndexTxEvents(curr.Ops)
if err != nil {
is.logger.Error("failed to index block txs",
"height", is.currentBlock.height, "err", err)
} else {
is.metrics.TxEventsSeconds.Observe(time.Since(start).Seconds())
is.metrics.TransactionsIndexed.Add(float64(curr.Size()))
is.logger.Debug("indexed txs",
"height", is.currentBlock.height, "sink", sink.Type())
}
go func() {
ops := curr.Ops
start := time.Now()
err := sink.IndexTxEvents(ops)
if err != nil {
is.logger.Error("failed to index block txs",
"height", is.currentBlock.height, "err", err)
} else {
is.metrics.TxEventsSeconds.Observe(time.Since(start).Seconds())
is.metrics.TransactionsIndexed.Add(float64(curr.Size()))
is.logger.Debug("indexed txs",
"height", is.currentBlock.height, "sink", sink.Type())
}
}()

}
}
is.currentBlock.batch = nil // return to the WAIT state for the next block
Expand Down

0 comments on commit a8d025b

Please sign in to comment.