Skip to content

Commit

Permalink
fix: scripts query empty result lead deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 13, 2023
1 parent 6d57d0b commit 5fe5acd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/controllers/api/v2/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,36 @@ 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
@ckb_transactions = @contract.ckb_transactions.order(id: :desc).page(@page).per(@page_size)
@ckb_transactions =
if @contract.ckb_transactions_count.zero?
CkbTransaction.none
else
@contract.ckb_transactions.order(id: :desc).page(@page).per(@page_size)
end
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)
@deployed_cells =
if @contract.deployed_cells_count.zero?
CellOutput.none
else
@contract.deployed_cell_outputs.live.page(@page).per(@page_size)
end
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)
@referring_cells =
if @contract.referring_cells_count.zero?
CellOutput.none
else
@contract.referring_cell_outputs.live.page(@page).per(@page_size)
end
end

private
Expand Down

0 comments on commit 5fe5acd

Please sign in to comment.