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

refactor: contract association ckb_transactions query #1461

Merged
merged 1 commit into from
Sep 22, 2023
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
9 changes: 3 additions & 6 deletions app/controllers/api/v2/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ def ckb_transactions
head :not_found and return if @contract.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
scope = CellDependency.where(contract_id: @contract.id).order(ckb_transaction_id: :desc)
tx_ids = scope.page(@page).per(@page_size).pluck(:ckb_transaction_id)
@ckb_transactions = CkbTransaction.find(tx_ids)
@total = scope.count
@ckb_transactions = @contract.ckb_transactions.order(id: :desc).page(@page).per(@page_size)
end

def deployed_cells
head :not_found and return if @contract.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
@deployed_cells = @contract.deployed_cell_outputs.live.page(@page).per(@page_size).fast_page
@deployed_cells = @contract.deployed_cell_outputs.live.page(@page).per(@page_size)
end

def referring_cells
head :not_found and return if @contract.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
@referring_cells = @contract.referring_cell_outputs.live.page(@page).per(@page_size).fast_page
@referring_cells = @contract.referring_cell_outputs.live.page(@page).per(@page_size)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/scripts/ckb_transactions.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ json.data do
json.display_outputs tx.display_outputs
end
json.meta do
json.total @total
json.total @contract.ckb_transactions_count
json.page_size @page_size.to_i
end
end
2 changes: 1 addition & 1 deletion app/views/api/v2/scripts/deployed_cells.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ json.data do
json.type_script_id deployed_cell.type_script_id
end
json.meta do
json.total @deployed_cells.total_count
json.total @contract.deployed_cells_count
json.page_size @page_size.to_i
end
end
2 changes: 1 addition & 1 deletion app/views/api/v2/scripts/referring_cells.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ json.data do
json.type_script_id referring_cell.type_script_id
end
json.meta do
json.total @referring_cells.total_count
json.total @contract.referring_cells_count
json.page_size @page_size.to_i
end
end