From d3c7c8636f5b43c30c01f7dec40a485f26589022 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 24 Jan 2019 22:32:19 +0300 Subject: [PATCH] add replaced_transaction update script --- ...ransaction_nonce_and_from_address_hash.exs | 13 ----------- .../scripts/update_replaced_transaction.sql | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 apps/explorer/priv/repo/migrations/scripts/update_replaced_transaction.sql diff --git a/apps/explorer/priv/repo/migrations/20190124082812_add_index_on_transaction_nonce_and_from_address_hash.exs b/apps/explorer/priv/repo/migrations/20190124082812_add_index_on_transaction_nonce_and_from_address_hash.exs index b899304c3b..0ceec61122 100644 --- a/apps/explorer/priv/repo/migrations/20190124082812_add_index_on_transaction_nonce_and_from_address_hash.exs +++ b/apps/explorer/priv/repo/migrations/20190124082812_add_index_on_transaction_nonce_and_from_address_hash.exs @@ -9,19 +9,6 @@ defmodule Explorer.Repo.Migrations.AddIndexOnTransactionNonceAndFromAddressHash def change do create(index(:transactions, [:nonce, :from_address_hash, :block_hash])) - # for replaced/dropeed transactions create(index(:transactions, [:block_hash, :error])) - - query = "UPDATE transactions SET error = 'dropped/replaced', status = 0 FROM transactions t1 - INNER JOIN transactions t2 - ON t1.from_address_hash = t2.from_address_hash AND t1.nonce = t2.nonce - WHERE t1.block_hash IS NULL AND t2.block_hash IS NOT NULL" - - SQL.query!( - Repo, - query, - [], - timeout: @timeout - ) end end diff --git a/apps/explorer/priv/repo/migrations/scripts/update_replaced_transaction.sql b/apps/explorer/priv/repo/migrations/scripts/update_replaced_transaction.sql new file mode 100644 index 0000000000..16f0765744 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/scripts/update_replaced_transaction.sql @@ -0,0 +1,23 @@ +DO $$ + DECLARE + start_time TIMESTAMP WITHOUT TIME ZONE := clock_timestamp(); + end_time TIMESTAMP WITHOUT TIME ZONE; + elapsed_time INTERVAL; + temp_start_time TIMESTAMP WITHOUT TIME ZONE; + temp_end_time TIMESTAMP WITHOUT TIME ZONE; + BEGIN + RAISE NOTICE 'Started at %', start_time; + + temp_start_time := clock_timestamp(); + + UPDATE transactions SET error = 'dropped/replaced', status = 0 FROM transactions t1 + INNER JOIN transactions t2 + ON t1.from_address_hash = t2.from_address_hash AND t1.nonce = t2.nonce + WHERE t1.block_hash IS NULL AND t2.block_hash IS NOT NULL; + + end_time := clock_timestamp(); + elapsed_time := end_time - start_time; + + RAISE NOTICE 'Ended at %s', end_time; + RAISE NOTICE 'Elapsed time: %', elapsed_time; +END $$;