Skip to content

Commit

Permalink
feat: add visible to address
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Dec 13, 2019
1 parent 16acdbc commit 61c5597
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Address < ApplicationRecord
has_many :ckb_transactions, through: :account_books
validates :balance, :cell_consumed, :ckb_transactions_count, :interest, :dao_deposit, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true

scope :visible, -> { where(visible: true) }

after_commit :flush_cache

def lock_script
Expand Down Expand Up @@ -65,6 +67,7 @@ def flush_cache
# dao_deposit :decimal(30, ) default(0)
# interest :decimal(30, ) default(0)
# block_timestamp :decimal(30, )
# visible :boolean default(TRUE)
#
# Indexes
#
Expand Down
2 changes: 1 addition & 1 deletion app/models/statistic_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def miner_ranking

def address_balance_ranking
Rails.cache.realize("address_balance_ranking", expires_in: 4.hours) do
addresses = Address.order(balance: :desc).limit(50)
addresses = Address.visible.order(balance: :desc).limit(50)
addresses.each.with_index(1).map do |address, index|
{ ranking: index.to_s, address: address.address_hash, balance: address.balance.to_s }
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20191213030520_add_visible_to_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVisibleToAddress < ActiveRecord::Migration[6.0]
def change
add_column :addresses, :visible, :boolean, default: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_12_09_054145) do
ActiveRecord::Schema.define(version: 2019_12_13_030520) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -36,6 +36,7 @@
t.decimal "dao_deposit", precision: 30, default: "0"
t.decimal "interest", precision: 30, default: "0"
t.decimal "block_timestamp", precision: 30
t.boolean "visible", default: true
t.index ["address_hash"], name: "index_addresses_on_address_hash"
t.index ["lock_hash"], name: "index_addresses_on_lock_hash", unique: true
end
Expand Down

0 comments on commit 61c5597

Please sign in to comment.