Skip to content

Commit

Permalink
fix(eventindexer): add indexes for struggling queries (#15483)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Jan 12, 2024
1 parent 62eebe4 commit 8b81028
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/eventindexer/.l2.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ DATABASE_HOST=localhost:3306
DATABASE_MAX_IDLE_CONNS=50
DATABASE_MAX_OPEN_CONNS=3000
DATABASE_CONN_MAX_LIFETIME_IN_MS=100000
RPC_URL=wss://ws.internal.taiko.xyz
RPC_URL=wss://ws.katla.taiko.xyz
CORS_ORIGINS=*
BLOCK_BATCH_SIZE=100
BLOCK_BATCH_SIZE=50
CACHE_INTERVAL_IN_SECONDS=60
LAYER=l2
INDEX_NFTS=true
8 changes: 4 additions & 4 deletions packages/eventindexer/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error {
case tasks.TotalTransitionProvedByTier:
var tiers []uint16 = make([]uint16, 0)

query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;"
query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;"

err = g.db.GormDB().
Raw(query, eventindexer.EventNameTransitionProved).
Expand Down Expand Up @@ -252,7 +252,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error {
case tasks.TransitionProvedByTierPerDay:
var tiers []uint16 = make([]uint16, 0)

query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;"
query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;"

err = g.db.GormDB().
Raw(query, eventindexer.EventNameTransitionProved).
Expand Down Expand Up @@ -301,7 +301,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error {
case tasks.TransitionContestedByTierPerDay:
var tiers []uint16 = make([]uint16, 0)

query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;"
query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;"

err = g.db.GormDB().
Raw(query, eventindexer.EventNameTransitionContested).
Expand Down Expand Up @@ -350,7 +350,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error {
case tasks.TotalTransitionContestedByTier:
var tiers []uint16 = make([]uint16, 0)

query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;"
query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;"

err = g.db.GormDB().
Raw(query, eventindexer.EventNameTransitionContested).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE `transactions` ADD INDEX transacted_at_index(`transacted_at`),
ADD INDEX transacted_at_contract_address_index(`transacted_at`, `contract_address`);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX transacted_at_index on transactions;
DROP INDEX transacted_at_contract_address_index on transactions;
-- +goose StatementEnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE `events` ADD INDEX `event_transacted_at_tier_index` (`transacted_at`, `event`, `tier`),
ADD INDEX `event_transacted_at_index` (`transacted_at`, `event`),
ADD INDEX `event_block_id_index` (`event`, `block_id`),
ADD INDEX `event_tier_index` (`event`, `tier`);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX event_transacted_at_tier_index on events,
event_transacted_at_index on events,
event_block_id_index on events,
event_tier_index on events;
-- +goose StatementEnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE `accounts` ADD INDEX `transacted_at_index` (`transacted_at`);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX transacted_at_index on accounts;
-- +goose StatementEnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE `blocks` ADD INDEX `transacted_at_index` (`transacted_at`);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX transacted_at_index on blocks;
-- +goose StatementEnd

2 comments on commit 8b81028

@vercel
Copy link

@vercel vercel bot commented on 8b81028 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-a6 – ./packages/bridge-ui-v2

bridge-ui-v2-a6.vercel.app
bridge-ui-v2-a6-git-alpha-6-taikoxyz.vercel.app
bridge-ui-v2-a6-taikoxyz.vercel.app
bridge.katla.taiko.xyz

@vercel
Copy link

@vercel vercel bot commented on 8b81028 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal-git-alpha-6-taikoxyz.vercel.app
bridge-ui-v2-internal.vercel.app
bridge-ui-v2-internal-taikoxyz.vercel.app

Please sign in to comment.