From e10bee726802836c6026065e516ac8be0ae25483 Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Sun, 23 Jul 2023 13:23:37 -0700 Subject: [PATCH] feat(eventindexer): speed up sync (#14258) --- packages/eventindexer/indexer/filter.go | 31 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/eventindexer/indexer/filter.go b/packages/eventindexer/indexer/filter.go index 81573cf0cd8..d2df6587894 100644 --- a/packages/eventindexer/indexer/filter.go +++ b/packages/eventindexer/indexer/filter.go @@ -5,9 +5,10 @@ import ( "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/labstack/gommon/log" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" + log "github.com/sirupsen/logrus" ) type FilterFunc func( @@ -162,18 +163,26 @@ func L2FilterFunc( svc *Service, filterOpts *bind.FilterOpts, ) error { + wg, ctx := errgroup.WithContext(ctx) + for _, s := range svc.swaps { - swaps, err := s.FilterSwap(filterOpts, nil, nil) - if err != nil { - return errors.Wrap(err, "svc.bridge.FilterSwap") - } + swap := s - // only save ones above 0.01 ETH, this is only for Galaxe - // and we dont care about the rest - err = svc.saveSwapEvents(ctx, chainID, swaps) - if err != nil { - return errors.Wrap(err, "svc.saveSwapEvents") - } + wg.Go(func() error { + swaps, err := swap.FilterSwap(filterOpts, nil, nil) + if err != nil { + return errors.Wrap(err, "svc.bridge.FilterSwap") + } + + // only save ones above 0.01 ETH, this is only for Galaxe + // and we dont care about the rest + err = svc.saveSwapEvents(ctx, chainID, swaps) + if err != nil { + return errors.Wrap(err, "svc.saveSwapEvents") + } + + return nil + }) } return nil