This caches the highest nonce value seen for sent transactions for a given address. The top addresses query no longer needs to scan the transactions table for nonce values. The database migration script adds the nonce field to the addresses table and sets the nonce value according to the contents of the transactions table.pull/1140/head
parent
2895b6c61b
commit
29199eb54e
@ -0,0 +1,30 @@ |
||||
defmodule Explorer.Repo.Migrations.AddNonceToAddresses do |
||||
use Ecto.Migration |
||||
|
||||
def up do |
||||
# Add nonce |
||||
alter table(:addresses) do |
||||
add(:nonce, :integer) |
||||
end |
||||
|
||||
# Populate nonce field from transactions table |
||||
execute(""" |
||||
WITH t AS ( |
||||
SELECT from_address_hash AS hash, MAX(nonce) AS nonce |
||||
FROM transactions |
||||
GROUP BY hash |
||||
) |
||||
UPDATE addresses AS a |
||||
SET nonce = t.nonce |
||||
FROM t |
||||
WHERE a.hash = t.hash |
||||
""") |
||||
end |
||||
|
||||
def down do |
||||
# Remove nonce |
||||
alter table(:addresses) do |
||||
remove(:nonce) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue