Skip to content

Commit

Permalink
Refactoring: sanitizer to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 3, 2023
1 parent 5168b26 commit 2bbbc39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
4 changes: 3 additions & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ type Cache struct {
}

// NewCache -
func NewCache(rpc noderpc.INode, accounts account.Repository, contracts contract.Repository, protocols protocol.Repository, sanitizer *bluemonday.Policy) *Cache {
func NewCache(rpc noderpc.INode, accounts account.Repository, contracts contract.Repository, protocols protocol.Repository) *Cache {
sanitizer := bluemonday.UGCPolicy()
sanitizer.AllowAttrs("em")
return &Cache{
ccache.New(ccache.Configure().MaxSize(1000)),
rpc,
Expand Down
10 changes: 3 additions & 7 deletions internal/config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/baking-bad/bcdhub/internal/postgres"
"github.com/baking-bad/bcdhub/internal/postgres/core"
"github.com/baking-bad/bcdhub/internal/services/mempool"
"github.com/microcosm-cc/bluemonday"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -51,24 +50,21 @@ type Context struct {
SmartRollups smartrollup.Repository
Partitions *postgres.PartitionManager

Cache *cache.Cache
Sanitizer *bluemonday.Policy
Cache *cache.Cache
}

// NewContext -
func NewContext(network types.Network, opts ...ContextOption) *Context {
ctx := &Context{
Sanitizer: bluemonday.UGCPolicy(),
Network: network,
Network: network,
}
ctx.Sanitizer.AllowAttrs("em")

for _, opt := range opts {
opt(ctx)
}

ctx.Cache = cache.NewCache(
ctx.RPC, ctx.Accounts, ctx.Contracts, ctx.Protocols, ctx.Sanitizer,
ctx.RPC, ctx.Accounts, ctx.Contracts, ctx.Protocols,
)
return ctx
}
Expand Down
23 changes: 11 additions & 12 deletions internal/parsers/operations/operation_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/baking-bad/bcdhub/internal/parsers"
"github.com/go-pg/pg/v10"
"github.com/golang/mock/gomock"
"github.com/microcosm-cc/bluemonday"
)

func TestGroup_Parse(t *testing.T) {
Expand Down Expand Up @@ -387,7 +386,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -423,7 +422,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -599,7 +598,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -785,7 +784,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -880,7 +879,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -982,7 +981,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -1168,7 +1167,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -1266,7 +1265,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -1401,7 +1400,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down Expand Up @@ -1470,7 +1469,7 @@ func TestGroup_Parse(t *testing.T) {
Operations: operaitonsRepo,
Scripts: scriptRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
storage: map[string]int64{
Expand Down Expand Up @@ -2073,7 +2072,7 @@ func TestGroup_Parse(t *testing.T) {
Scripts: scriptRepo,
GlobalConstants: globalConstantRepo,
Cache: cache.NewCache(
rpc, accountsRepo, contractRepo, protoRepo, bluemonday.UGCPolicy(),
rpc, accountsRepo, contractRepo, protoRepo,
),
},
paramsOpts: []ParseParamsOption{
Expand Down

0 comments on commit 2bbbc39

Please sign in to comment.