Skip to content

Commit

Permalink
perf: speed up epoch statistic generator
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Apr 30, 2020
1 parent 2c40104 commit f3a059a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/charts/epoch_statistic_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def call
uncles_count = Block.where(epoch: target_epoch_number).sum(:uncles_count)
uncle_rate = uncles_count / blocks_count.to_d
difficulty = Block.where(epoch: target_epoch_number).first.difficulty
first_block_in_epoch = Block.where(epoch: target_epoch_number).order(:number).first
last_lock_in_epoch = Block.where(epoch: target_epoch_number).order(:number).last
first_block_in_epoch = Block.where(epoch: target_epoch_number).order(:number).select(:timestamp)[0]
last_lock_in_epoch = Block.where(epoch: target_epoch_number).order(number: :desc).select(:timestamp)[0]
epoch_time = last_lock_in_epoch.timestamp - first_block_in_epoch.timestamp
epoch_length = Block.where(epoch: target_epoch_number).count
hash_rate = difficulty * epoch_length / epoch_time
Expand Down

0 comments on commit f3a059a

Please sign in to comment.