From 2fbc9f6009bbd0657fca42a330632b00de9296a2 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 15 Jan 2025 17:50:11 +0800 Subject: [PATCH] fix: add secondary order (#2408) Signed-off-by: Miles Zhang --- app/controllers/api/v1/blocks_controller.rb | 14 +++++++------- .../api/v1/omiga_inscriptions_controller.rb | 2 +- app/controllers/api/v1/udts_controller.rb | 2 +- app/controllers/api/v1/xudts_controller.rb | 2 +- .../api/v2/pending_transactions_controller.rb | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/v1/blocks_controller.rb b/app/controllers/api/v1/blocks_controller.rb index cfbb941b1..4af482a8a 100644 --- a/app/controllers/api/v1/blocks_controller.rb +++ b/app/controllers/api/v1/blocks_controller.rb @@ -20,17 +20,17 @@ def index order_by, asc_or_desc = params[:sort].split(".", 2) order_by = case order_by - when "height" - "number" - when "transactions" - "ckb_transactions_count" - else - order_by + when "height" + "number" + when "transactions" + "ckb_transactions_count" + else + order_by end head :not_found and return unless order_by.in? %w[number reward timestamp ckb_transactions_count] - blocks = blocks.order(order_by => asc_or_desc).page(@page).per(@page_size) + blocks = blocks.order(order_by => asc_or_desc).order("number DESC").page(@page).per(@page_size) json = Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do diff --git a/app/controllers/api/v1/omiga_inscriptions_controller.rb b/app/controllers/api/v1/omiga_inscriptions_controller.rb index e9785bcf0..8d524c997 100644 --- a/app/controllers/api/v1/omiga_inscriptions_controller.rb +++ b/app/controllers/api/v1/omiga_inscriptions_controller.rb @@ -93,7 +93,7 @@ def sort_udts(records) if sort == "mint_status" records.joins(:omiga_inscription_info).order("omiga_inscription_infos.mint_status #{order}") else - records.order("#{sort} #{order}") + records.order("#{sort} #{order}").order("full_name ASC, id ASC") end end end diff --git a/app/controllers/api/v1/udts_controller.rb b/app/controllers/api/v1/udts_controller.rb index ccc31a978..d38a8188f 100644 --- a/app/controllers/api/v1/udts_controller.rb +++ b/app/controllers/api/v1/udts_controller.rb @@ -135,7 +135,7 @@ def sort_udts(records) order = "asc" end - records.order("#{sort} #{order}") + records.order("#{sort} #{order}").order("full_name ASC, id ASC") end end end diff --git a/app/controllers/api/v1/xudts_controller.rb b/app/controllers/api/v1/xudts_controller.rb index 5c7ee86bb..4e0a1ec76 100644 --- a/app/controllers/api/v1/xudts_controller.rb +++ b/app/controllers/api/v1/xudts_controller.rb @@ -101,7 +101,7 @@ def sort_udts(records) order = "asc" end - records.order("#{sort} #{order}") + records.order("#{sort} #{order}").order("full_name ASC, id ASC") end def parse_tags diff --git a/app/controllers/api/v2/pending_transactions_controller.rb b/app/controllers/api/v2/pending_transactions_controller.rb index 18a3f18c1..68a5baf57 100644 --- a/app/controllers/api/v2/pending_transactions_controller.rb +++ b/app/controllers/api/v2/pending_transactions_controller.rb @@ -11,7 +11,7 @@ def index where.not(previous_cell_output_id: nil, from_cell_base: false). pluck(:ckb_transaction_id).uniq pending_transactions = CkbTransaction.where(id: unique_tx_ids). - order(transactions_ordering).page(@page).per(@page_size) + order(transactions_ordering).order("id DESC").page(@page).per(@page_size) json = { data: pending_transactions.map do |tx| @@ -20,13 +20,13 @@ def index capacity_involved: tx.capacity_involved, transaction_fee: tx.transaction_fee, created_at: tx.created_at, - create_timestamp: (tx.created_at.to_f * 1000).to_i + create_timestamp: (tx.created_at.to_f * 1000).to_i, } end, meta: { total: pending_transactions.total_count, - page_size: @page_size.to_i - } + page_size: @page_size.to_i, + }, } render json: json @@ -34,7 +34,7 @@ def index def count render json: { - data: CkbTransaction.tx_pending.count + data: CkbTransaction.tx_pending.count, } end