Skip to content

Commit

Permalink
refactor: holder_count query (#2074)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Jul 17, 2024
1 parent 51c08f9 commit ac88737
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/daily_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,11 @@ def liquidity
end

define_logic :holder_count do
live_address_ids = CellOutput.live.generated_before(to_be_counted_date.to_i * 1000 - 1).pluck(:address_id)
dead_address_ids = CellOutput.dead.generated_before(to_be_counted_date.to_i * 1000 - 1).consumed_after(to_be_counted_date.to_i * 1000).pluck(:address_id)
(live_address_ids + dead_address_ids).uniq.count
live_query = CellOutput.live.generated_before(to_be_counted_date.to_i * 1000 - 1).select(:address_id).to_sql
dead_query = CellOutput.dead.generated_before(to_be_counted_date.to_i * 1000 - 1).consumed_after(to_be_counted_date.to_i * 1000).select(:address_id).to_sql
combined_query = "#{live_query} UNION #{dead_query}"
count_query = "SELECT COUNT(DISTINCT address_id) AS count FROM (#{combined_query}) AS combined_results;"
ActiveRecord::Base.connection.execute(count_query).first["count"]
end

private
Expand Down

0 comments on commit ac88737

Please sign in to comment.