perf: Enhance index for token holders list (#9816)

* Enhance index for token holders list

* Separate index creation and deletion to different migrations
pull/9904/head
Victor Baranov 7 months ago committed by GitHub
parent c08ea4782c
commit df660c90c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      apps/explorer/priv/repo/migrations/20240404102510_enhance_index_for_token_holders_list.exs
  2. 14
      apps/explorer/priv/repo/migrations/20240404102511_drop_outdated_index_for_token_holders_list.exs

@ -0,0 +1,14 @@
defmodule Explorer.Repo.Migrations.EnhanceIndexForTokenHoldersList do
use Ecto.Migration
@disable_ddl_transaction true
@disable_migration_lock true
def change do
create_if_not_exists(
index(:address_current_token_balances, ["token_contract_address_hash, value DESC, address_hash DESC"],
where: "address_hash != '\\x0000000000000000000000000000000000000000' AND value > 0",
concurrently: true
)
)
end
end

@ -0,0 +1,14 @@
defmodule Explorer.Repo.Migrations.DropOutdatedIndexForTokenHoldersList do
use Ecto.Migration
@disable_ddl_transaction true
@disable_migration_lock true
def change do
drop_if_exists(
index(:address_current_token_balances, [:token_contract_address_hash],
where: "address_hash != '\\x0000000000000000000000000000000000000000' AND value > 0",
concurrently: true
)
)
end
end
Loading…
Cancel
Save