Skip to content

Commit 7414c92

Browse files
authored
Merge pull request #2658 from nervosnetwork/testnet
Deploy to mainnet
2 parents 355a699 + b56b687 commit 7414c92

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

app/models/block.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def self.fetch_transaction_fee_rate_from_cache(date_string)
8181
end
8282

8383
def self.last_7_days_ckb_node_version
84-
from = 7.days.ago.to_i * 1000
85-
sql = "select ckb_node_version, count(*) from blocks where timestamp >= #{from} group by ckb_node_version order by 1 asc;"
84+
# for better query performance, we use epoch instead of timestamp here, it will utilize the index of `blocks.epoch`.
85+
# one epoch is 4 hours approximately, so we can get the last 42 epochs
86+
from = self.tip_block.epoch - 42
87+
sql = "select ckb_node_version, count(*) from blocks where epoch >= #{from} group by ckb_node_version order by 1 asc;"
8688
connection.execute(sql).values
8789
end
8890

test/models/block_test.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,6 @@ class BlockTest < ActiveSupport::TestCase
277277
block.proposals
278278
end
279279

280-
test "it should get last_7_days_ckb_node_version" do
281-
result_last_7_days_ckb_node_version = Block.last_7_days_ckb_node_version
282-
from = 7.days.ago.to_i * 1000
283-
sql = "select ckb_node_version, count(*) from blocks where timestamp >= #{from} group by ckb_node_version;"
284-
result_sql = ActiveRecord::Base.connection.execute(sql).values
285-
286-
assert_equal result_last_7_days_ckb_node_version, result_sql
287-
end
288-
289280
test "cached_find not always return nil" do
290281
assert_nil Block.cached_find("111111")
291282
create(:block, number: 111111)

0 commit comments

Comments
 (0)