Skip to content

Commit

Permalink
Fix: token savings
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 14, 2024
1 parent 240c9a5 commit db24b9b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
9 changes: 3 additions & 6 deletions internal/storage/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ func (t Transaction) SaveTokens(ctx context.Context, tokens ...*models.Token) er
if len(tokens) == 0 {
return nil
}

values := t.Tx().NewValues(&tokens).Column("first_height", "contract_id", "token_id", "type")
_, err := t.Tx().NewInsert().Column("first_height", "contract_id", "token_id", "type").
With("_data", values).
Model((*models.Token)(nil)).
_, err := t.Tx().
NewInsert().
Model(&tokens).
On("CONFLICT ON CONSTRAINT token_unique_id DO NOTHING").
TableExpr("_data").
Exec(ctx)
return err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/postgres/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ func (s *TransactionTest) TestTokens() {

err = tx.SaveTokens(ctx, tokens...)
s.Require().NoError(err)
s.Require().Greater(tokens[0].ID, uint64(0))
s.Require().Greater(tokens[1].ID, uint64(0))

err = tx.Flush(ctx)
s.Require().NoError(err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/indexer/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
models "github.com/dipdup-io/starknet-indexer/internal/storage"
"github.com/dipdup-io/starknet-indexer/internal/storage/postgres"
"github.com/dipdup-io/starknet-indexer/pkg/indexer/cache"
"github.com/dipdup-io/starknet-indexer/pkg/indexer/parser/data"
parserData "github.com/dipdup-io/starknet-indexer/pkg/indexer/parser/data"
"github.com/dipdup-net/go-lib/database"
"github.com/dipdup-net/indexer-sdk/pkg/storage"
Expand Down Expand Up @@ -104,7 +103,7 @@ func (store *Store) Save(
}

if result.Block.TxCount > 0 {
sm := newSubModels(store.internals, store.transfers, store.events)
sm := newSubModels()

if err := store.saveDeclare(ctx, tx, result, sm); err != nil {
return tx.HandleError(ctx, err)
Expand Down Expand Up @@ -189,7 +188,7 @@ func (store *Store) saveInternals(
return nil
}

func (store *Store) saveProxies(ctx context.Context, tx postgres.Transaction, proxies data.ProxyMap[*models.ProxyUpgrade]) error {
func (store *Store) saveProxies(ctx context.Context, tx postgres.Transaction, proxies parserData.ProxyMap[*models.ProxyUpgrade]) error {
return proxies.Range(func(_ parserData.ProxyKey, value *models.ProxyUpgrade) (bool, error) {
store.cache.SetProxy(value.Hash, value.Selector, value.ToProxy())
if err := tx.Add(ctx, value); err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/indexer/store/sub_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ type subModels struct {
Internals []models.Internal
}

func newSubModels(
internalsStorage models.IInternal,
transfersStorage models.ITransfer,
eventsStorage models.IEvent,
) *subModels {
func newSubModels() *subModels {
return &subModels{
Transfers: make([]models.Transfer, 0),
Events: make([]models.Event, 0),
Expand Down

0 comments on commit db24b9b

Please sign in to comment.