Skip to content

Commit

Permalink
perf: query used columns only and avoid to use limit
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Dec 18, 2020
1 parent 2ad2b6c commit 73a669d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/lock_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def lock_info
block_interval = (epoch_number * 1800 + since_value_index * 1800 / since_value.length) - (tip_epoch.number * 1800 + tip_epoch.index * 1800 / tip_epoch.length)

if block_interval.negative?
block = Block.where(epoch: since_value.number).recent.first
block = Block.where(epoch: since_value.number).order(number: :desc).select(:start_number, :length)[0]
new_index = since_value_index < block.length ? since_value_index : since_value_index * block.length / since_value.length
block_timestamp = Block.where(number: block.start_number + new_index).pick(:timestamp)
estimated_unlock_time = DateTime.strptime(block_timestamp.to_s, "%Q")
Expand Down

0 comments on commit 73a669d

Please sign in to comment.