diff --git a/app/workers/generate_rgbpp_assets_statistic_worker.rb b/app/workers/generate_rgbpp_assets_statistic_worker.rb index badc1b99e..364845c46 100644 --- a/app/workers/generate_rgbpp_assets_statistic_worker.rb +++ b/app/workers/generate_rgbpp_assets_statistic_worker.rb @@ -2,7 +2,10 @@ class GenerateRgbppAssetsStatisticWorker include Sidekiq::Job sidekiq_options queue: "rgbpp" - def perform + attr_accessor :datetime + + def perform(datetime = nil) + @datetime = datetime statistic_attributes = [ ft_count_attributes, dob_count_attributes, @@ -11,9 +14,6 @@ def perform btc_holders_count_attributes, ckb_holders_count_attributes, ] - - puts "====" - puts statistic_attributes statistic_attributes.each { _1[:created_at_unixtimestamp] = started_at.to_i } RgbppAssetsStatistic.upsert_all(statistic_attributes, unique_by: %i[indicator network created_at_unixtimestamp]) rescue StandardError => e @@ -23,12 +23,13 @@ def perform private def ft_count_attributes - xudts_count = Udt.published_xudt.joins(:xudt_tag).where("xudt_tags.tags && ARRAY[?]::varchar[]", ["rgb++"]).count + xudts_count = Udt.published_xudt.where(created_at: ..ended_at).count { indicator: "ft_count", value: xudts_count, network: "global" } end def dob_count_attributes - token_collections_count = TokenCollection.where("tags && ARRAY[?]::varchar[]", ["rgb++"]).count + token_collections_count = TokenCollection.where("tags && ARRAY[?]::varchar[]", ["rgb++"]). + where(created_at: ..ended_at).count { indicator: "dob_count", value: token_collections_count, network: "global" } end @@ -49,18 +50,24 @@ def btc_holders_count_attributes udt_types = %i[xudt xudt_compatible spore_cell did_cell] udt_ids = Udt.where(udt_type: udt_types, published: true).ids address_ids = UdtAccount.where(udt_id: udt_ids).where("amount > 0").pluck(:address_id).uniq - holders_count = BitcoinAddressMapping.where(ckb_address_id: address_ids).distinct.count(:bitcoin_address_id) + holders_count = BitcoinAddressMapping.where(ckb_address_id: address_ids, created_at: ..ended_at). + distinct.count(:bitcoin_address_id) { indicator: "holders_count", value: holders_count, network: "btc" } end def ckb_holders_count_attributes udt_types = %i[xudt xudt_compatible spore_cell did_cell] udt_ids = Udt.where(udt_type: udt_types, published: true).ids - holders_count = UdtAccount.where(udt_id: udt_ids).where("amount > 0").distinct.count(:address_id) + holders_count = UdtAccount.where(udt_id: udt_ids, created_at: ..ended_at). + where("amount > 0").distinct.count(:address_id) { indicator: "holders_count", value: holders_count, network: "ckb" } end def to_be_counted_date + if @datetime.present? + return Time.zone.parse(@datetime) + end + last_record = UdtHourlyStatistic.order(created_at_unixtimestamp: :desc).first if last_record Time.zone.at(last_record.created_at_unixtimestamp) + 1.day