Skip to content

Commit

Permalink
Try no limiters
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrel-b committed Apr 10, 2024
1 parent 4e33afb commit eb704c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 367 deletions.
46 changes: 6 additions & 40 deletions server/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"context"
"database/sql"
"net/http"
"time"

"github.com/google/wire"
"github.com/jackc/pgx/v4/pgxpool"

db "github.com/mikeydub/go-gallery/db/gen/coredb"
"github.com/mikeydub/go-gallery/service/limiters"
"github.com/mikeydub/go-gallery/service/multichain"
"github.com/mikeydub/go-gallery/service/multichain/indexer"
"github.com/mikeydub/go-gallery/service/multichain/poap"
Expand All @@ -30,7 +28,6 @@ import (
"github.com/mikeydub/go-gallery/service/task"
"github.com/mikeydub/go-gallery/service/tokenmanage"
"github.com/mikeydub/go-gallery/util"
"github.com/mikeydub/go-gallery/util/retry"
)

// envInit is a type returned after setting up the environment
Expand All @@ -46,7 +43,6 @@ func NewMultichainProvider(ctx context.Context, envFunc func()) (*multichain.Pro
newTokenManageCache,
postgres.NewRepositories,
dbConnSet,
newReservoirLimiter, // needs to be a singleton
wire.Struct(new(multichain.ChainProvider), "*"),
multichainProviderInjector,
ethInjector,
Expand All @@ -73,18 +69,6 @@ func setEnv(f func()) envInit {
return envInit{}
}

type reservoirLimiter limiters.KeyRateLimiter

// Dumb forward method to satisfy the retry.Limiter interface
func (r *reservoirLimiter) ForKey(ctx context.Context, key string) (bool, time.Duration, error) {
return (*limiters.KeyRateLimiter)(r).ForKey(ctx, key)
}

func newReservoirLimiter(ctx context.Context, c *redis.Cache) *reservoirLimiter {
l := limiters.NewKeyRateLimiter(ctx, c, "retryer:reservoir", 120, time.Minute)
return util.ToPointer(reservoirLimiter(*l))
}

func newPqClient(e envInit) (*sql.DB, func()) {
pq := postgres.MustCreateClient()
return pq, func() { pq.Close() }
Expand Down Expand Up @@ -131,7 +115,7 @@ func customMetadataHandlersInjector(simplehashProvider *simplehash.Provider) *mu
))
}

func ethInjector(envInit, context.Context, *http.Client, *reservoirLimiter) (*multichain.EthereumProvider, func()) {
func ethInjector(envInit, context.Context, *http.Client) (*multichain.EthereumProvider, func()) {
panic(wire.Build(
rpc.NewEthClient,
wire.Value(persist.ChainETH),
Expand Down Expand Up @@ -169,7 +153,6 @@ func ethSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -178,8 +161,6 @@ func ethSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}
Expand All @@ -206,7 +187,7 @@ func tezosProviderInjector(tezosProvider *tezos.Provider, tzktProvider *tzkt.Pro
))
}

func optimismInjector(context.Context, *http.Client, *reservoirLimiter) (*multichain.OptimismProvider, func()) {
func optimismInjector(context.Context, *http.Client) (*multichain.OptimismProvider, func()) {
panic(wire.Build(
wire.Value(persist.ChainOptimism),
simplehash.NewProvider,
Expand Down Expand Up @@ -237,7 +218,6 @@ func optimismSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -246,13 +226,11 @@ func optimismSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}

func arbitrumInjector(context.Context, *http.Client, *reservoirLimiter) (*multichain.ArbitrumProvider, func()) {
func arbitrumInjector(context.Context, *http.Client) (*multichain.ArbitrumProvider, func()) {
panic(wire.Build(
wire.Value(persist.ChainArbitrum),
simplehash.NewProvider,
Expand Down Expand Up @@ -283,7 +261,6 @@ func arbitrumSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -292,8 +269,6 @@ func arbitrumSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}
Expand All @@ -315,7 +290,7 @@ func poapProviderInjector(poapProvider *poap.Provider) *multichain.PoapProvider
))
}

func zoraInjector(envInit, context.Context, *http.Client, *reservoirLimiter) (*multichain.ZoraProvider, func()) {
func zoraInjector(envInit, context.Context, *http.Client) (*multichain.ZoraProvider, func()) {
panic(wire.Build(
wire.Value(persist.ChainZora),
simplehash.NewProvider,
Expand Down Expand Up @@ -347,7 +322,6 @@ func zoraSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -356,13 +330,11 @@ func zoraSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}

func baseInjector(context.Context, *http.Client, *reservoirLimiter) (*multichain.BaseProvider, func()) {
func baseInjector(context.Context, *http.Client) (*multichain.BaseProvider, func()) {
panic(wire.Build(
wire.Value(persist.ChainBase),
simplehash.NewProvider,
Expand Down Expand Up @@ -393,7 +365,6 @@ func baseSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -402,13 +373,11 @@ func baseSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}

func polygonInjector(context.Context, *http.Client, *reservoirLimiter) (*multichain.PolygonProvider, func()) {
func polygonInjector(context.Context, *http.Client) (*multichain.PolygonProvider, func()) {
panic(wire.Build(
wire.Value(persist.ChainPolygon),
simplehash.NewProvider,
Expand Down Expand Up @@ -439,7 +408,6 @@ func polygonSyncPipelineInjector(
httpClient *http.Client,
chain persist.Chain,
simplehashProvider *simplehash.Provider,
l *reservoirLimiter,
) (*wrapper.SyncPipelineWrapper, func()) {
panic(wire.Build(
wire.Struct(new(wrapper.SyncPipelineWrapper), "*"),
Expand All @@ -448,8 +416,6 @@ func polygonSyncPipelineInjector(
wire.Bind(new(multichain.TokensIncrementalContractFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokenMetadataBatcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(multichain.TokensByTokenIdentifiersFetcher), util.ToPointer(simplehashProvider)),
wire.Bind(new(retry.Limiter), util.ToPointer(l)),
wrapper.NewFillInWrapper,
customMetadataHandlersInjector,
))
}
Expand Down
Loading

0 comments on commit eb704c9

Please sign in to comment.