diff --git a/app/interactions/addresses/ckb_transactions.rb b/app/interactions/addresses/ckb_transactions.rb index 6bf58b200..4a88a7f50 100644 --- a/app/interactions/addresses/ckb_transactions.rb +++ b/app/interactions/addresses/ckb_transactions.rb @@ -13,14 +13,10 @@ def execute raise AddressNotFoundError if address.is_a?(NullAddress) address_id = address.map(&:id) - account_books = AccountBook.joins(:ckb_transaction). - where(account_books: { address_id: }, ckb_transactions: { tx_status: :committed }). - order(transactions_ordering). - select("DISTINCT account_books.ckb_transaction_id, ckb_transactions.block_timestamp, ckb_transactions.tx_index"). - page(page).per(page_size) - records = CkbTransaction.where(id: account_books.map(&:ckb_transaction_id)).order(transactions_ordering) + account_books = AccountBook.where(address_id:).order("ckb_transaction_id desc").select(:ckb_transaction_id).distinct.limit(5000) + records = CkbTransaction.where(tx_status: :committed, id: account_books.map(&:ckb_transaction_id)).order(transactions_ordering).page(page).per(page_size) options = paginate_options(records, address_id) - options.merge!(params: { previews: true, address: }) + options.merge!(params: { previews: false, address: }) result = CkbTransactionsSerializer.new(records, options) wrap_result(result, address) @@ -37,10 +33,7 @@ def transactions_ordering end def paginate_options(records, address_id) - total_count = AccountBook.includes(:ckb_transaction).where( - account_books: { address_id: }, - ckb_transactions: { tx_status: :committed }, - ).distinct.count(:ckb_transaction_id) + total_count = AccountBook.where(address_id:).distinct.count FastJsonapi::PaginationMetaGenerator.new( request:, records:, page:, page_size:, total_count:, ).call diff --git a/app/interactions/addresses/pending_transactions.rb b/app/interactions/addresses/pending_transactions.rb index 191887f67..ea41d0d8b 100644 --- a/app/interactions/addresses/pending_transactions.rb +++ b/app/interactions/addresses/pending_transactions.rb @@ -12,17 +12,8 @@ def execute address = Explore.run!(key:) raise AddressNotFoundError if address.is_a?(NullAddress) - account_books = - AccountBook.joins(:ckb_transaction).where( - account_books: { address_id: address.map(&:id) }, - ckb_transactions: { tx_status: "pending" }, - ) - ckb_transaction_ids = - CellInput.where(ckb_transaction_id: account_books.map(&:ckb_transaction_id)). - where.not(previous_cell_output_id: nil, from_cell_base: false). - distinct.pluck(:ckb_transaction_id) records = - CkbTransaction.where(id: ckb_transaction_ids). + CkbTransaction.joins(:account_books).where(ckb_transactions: { tx_status: :pending }, account_books: { address_id: address.map(&:id) }). select(select_fields). order(transactions_ordering). page(page).per(page_size)