Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add secondary order #2408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/controllers/api/v1/blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
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"

Check warning on line 24 in app/controllers/api/v1/blocks_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v1/blocks_controller.rb#L24

Added line #L24 was not covered by tests
when "transactions"
"ckb_transactions_count"

Check warning on line 26 in app/controllers/api/v1/blocks_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v1/blocks_controller.rb#L26

Added line #L26 was not covered by tests
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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/omiga_inscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/udts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/xudts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v2/pending_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -20,21 +20,21 @@ 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
end

def count
render json: {
data: CkbTransaction.tx_pending.count
data: CkbTransaction.tx_pending.count,
}
end

Expand Down
Loading