class Hive::Block

Tracks blocks.

To find blocks that have promoted posts:

blocks = Hive::Block.with_promoted_posts

With this result, we can get a list of post promoters in that block:

accounts = blocks.first.post_promoters

To find blocks that have normal intervals:

blocks = Hive::Block.block_interval(is: 3.seconds)

To find blocks that have longer than normal intervals:

blocks = Hive::Block.block_interval(min: 4.seconds)

To find blocks that have shorter than normal intervals:

blocks = Hive::Block.block_interval(max: 2.seconds)

To find blocks that have intervals in a certain range:

blocks = Hive::Block.block_interval(min: 15.seconds, max: 30.seconds)

Full report of slow blocks on the entire chain, grouped by date, sorted by the total slow blocks for that day:

puts JSON.pretty_generate Hive::Block.block_interval(min: 4.seconds).
  group('CAST(hive_blocks.created_at AS DATE)').order("count_all").count

Same report as above, grouped by month, sorted by the total slow blocks for that month:

puts JSON.pretty_generate Hive::Block.block_interval(min: 4.seconds).
  group("TO_CHAR(hive_blocks.created_at, 'YYYY-MM')").order("count_all").count

Same report as above, sorted by month:

puts JSON.pretty_generate Hive::Block.block_interval(min: 4.seconds).
  group("TO_CHAR(hive_blocks.created_at, 'YYYY-MM')").
  order("to_char_hive_blocks_created_at_yyyy_mm").count

Private Class Methods

block_interval_column(units = :seconds) click to toggle source
# File lib/hive/models/block.rb, line 84
def self.block_interval_column(units = :seconds)
  "EXTRACT(#{units} FROM hive_blocks.created_at - previous_hive_blocks.created_at)"
end