Skip to content

Commit

Permalink
Merge pull request #749 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
fix: dao contract cache bug
  • Loading branch information
shaojunda authored Nov 29, 2020
2 parents 0c9b649 + bf03428 commit 11b025e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/contracts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class ContractsController < ApplicationController
def show
raise Api::V1::Exceptions::ContractNotFoundError if params[:id] != DaoContract::CONTRACT_NAME

dao_contract = DaoContract.where(id: 1)
dao_contract = DaoContract.default_contract
json =
Rails.cache.realize(dao_contract.cache_key, version: dao_contract.cache_version, race_condition_ttl: 3.seconds) do
DaoContractSerializer.new(dao_contract.first).serialized_json
DaoContractSerializer.new(dao_contract).serialized_json
end

render json: json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class AddressUdtTransactionsControllerTest < ActionDispatch::IntegrationTest
page_size = 5
udt = create(:udt, published: true)
address = create(:address, :with_udt_transactions, transactions_count: 30, udt: udt)
address_udt_transactions = address.ckb_udt_transactions(udt.id).order(block_timestamp: :desc).page(page).per(page_size)
address_udt_transactions = address.ckb_udt_transactions(udt.id).order("block_timestamp desc nulls last, id desc").page(page).per(page_size)

valid_get api_v1_address_udt_transaction_url(address.address_hash, type_hash: udt.type_hash), params: { page: page, page_size: page_size }
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: address_udt_transactions, page: page, page_size: page_size).call
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/api/v1/contracts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class ContractsControllerTest < ActionDispatch::IntegrationTest

assert_equal response_json, response.body
end


test "should update dao contract cache when dao related data changed" do
dao_contract = DaoContract.default_contract
cache_version = dao_contract.cache_version
dao_contract.touch
assert_not_equal cache_version, dao_contract.reload.cache_version
end
end
end
end

0 comments on commit 11b025e

Please sign in to comment.