Skip to content

Commit

Permalink
Merge pull request #447 from bitcoin-sv/clear-status-update-map
Browse files Browse the repository at this point in the history
clear map properly
  • Loading branch information
shotasilagadzetaal authored Jun 7, 2024
2 parents d78430b + 53f9724 commit d129c75
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/metamorph/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,20 @@ func (p *Processor) StartProcessMinedCallbacks() {
}()
}

func (p *Processor) CheckAndUpdate(statusUpdatesMap *map[chainhash.Hash]store.UpdateStatus) {
if len(*statusUpdatesMap) == 0 {
func (p *Processor) CheckAndUpdate(statusUpdatesMap map[chainhash.Hash]store.UpdateStatus) {
if len(statusUpdatesMap) == 0 {
return
}

statusUpdates := make([]store.UpdateStatus, 0, p.processStatusUpdatesBatchSize)
for _, distinctStatusUpdate := range *statusUpdatesMap {
for _, distinctStatusUpdate := range statusUpdatesMap {
statusUpdates = append(statusUpdates, distinctStatusUpdate)
}

err := p.statusUpdateWithCallback(statusUpdates)
if err != nil {
p.logger.Error("failed to bulk update statuses", slog.String("err", err.Error()))
}

*statusUpdatesMap = map[chainhash.Hash]store.UpdateStatus{}
}

func (p *Processor) StartProcessStatusUpdatesInStorage() {
Expand All @@ -306,10 +304,14 @@ func (p *Processor) StartProcessStatusUpdatesInStorage() {
}

if len(statusUpdatesMap) >= p.processStatusUpdatesBatchSize {
p.CheckAndUpdate(&statusUpdatesMap)
p.CheckAndUpdate(statusUpdatesMap)
statusUpdatesMap = map[chainhash.Hash]store.UpdateStatus{}
}
case <-ticker.C:
p.CheckAndUpdate(&statusUpdatesMap)
if len(statusUpdatesMap) > 0 {
p.CheckAndUpdate(statusUpdatesMap)
statusUpdatesMap = map[chainhash.Hash]store.UpdateStatus{}
}
}
}
}()
Expand Down

0 comments on commit d129c75

Please sign in to comment.