File tree Expand file tree Collapse file tree 2 files changed +4
-11
lines changed
Expand file tree Collapse file tree 2 files changed +4
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments