diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 84c6fb640..ad063cb04 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -846,8 +846,9 @@ def build_cells_and_locks!( build_cell_outputs!(node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids) if cell_outputs_attributes.present? - tx_ids = cell_outputs_attributes.map { |attr| attr[:ckb_transaction_id] } - CellOutput.pending.where(ckb_transaction_id: tx_ids).update_all(status: :live) + tx_hashes = cell_outputs_attributes.map { |attr| attr[:tx_hash] } + binary_hashes = CkbUtils.hexes_to_bins_sql(tx_hashes) + CellOutput.pending.where("tx_hash IN (#{binary_hashes})").update_all(status: :live) id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index status], returning: %i[id data_hash]) cell_data_attrs = [] diff --git a/app/models/daily_statistic.rb b/app/models/daily_statistic.rb index 0986d8dd8..deebd9db7 100644 --- a/app/models/daily_statistic.rb +++ b/app/models/daily_statistic.rb @@ -399,9 +399,11 @@ def liquidity end define_logic :holder_count do - live_address_ids = CellOutput.live.generated_before(to_be_counted_date.to_i * 1000 - 1).pluck(:address_id) - dead_address_ids = CellOutput.dead.generated_before(to_be_counted_date.to_i * 1000 - 1).consumed_after(to_be_counted_date.to_i * 1000).pluck(:address_id) - (live_address_ids + dead_address_ids).uniq.count + live_query = CellOutput.live.generated_before(to_be_counted_date.to_i * 1000 - 1).select(:address_id).to_sql + dead_query = CellOutput.dead.generated_before(to_be_counted_date.to_i * 1000 - 1).consumed_after(to_be_counted_date.to_i * 1000).select(:address_id).to_sql + combined_query = "#{live_query} UNION #{dead_query}" + count_query = "SELECT COUNT(DISTINCT address_id) AS count FROM (#{combined_query}) AS combined_results;" + ActiveRecord::Base.connection.execute(count_query).first["count"] end private