Skip to content

Commit bf03428

Browse files
authored
Merge pull request #748 from nervosnetwork/shaojunda-fix-dao-cache-update
fix: dao cache update
2 parents df3f1e4 + 620274b commit bf03428

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

app/controllers/api/v1/contracts_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ class ContractsController < ApplicationController
44
def show
55
raise Api::V1::Exceptions::ContractNotFoundError if params[:id] != DaoContract::CONTRACT_NAME
66

7-
dao_contract = DaoContract.where(id: 1)
7+
dao_contract = DaoContract.default_contract
88
json =
99
Rails.cache.realize(dao_contract.cache_key, version: dao_contract.cache_version, race_condition_ttl: 3.seconds) do
10-
DaoContractSerializer.new(dao_contract.first).serialized_json
10+
DaoContractSerializer.new(dao_contract).serialized_json
1111
end
1212

1313
render json: json

test/controllers/api/v1/address_udt_transactions_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class AddressUdtTransactionsControllerTest < ActionDispatch::IntegrationTest
200200
page_size = 5
201201
udt = create(:udt, published: true)
202202
address = create(:address, :with_udt_transactions, transactions_count: 30, udt: udt)
203-
address_udt_transactions = address.ckb_udt_transactions(udt.id).order(block_timestamp: :desc).page(page).per(page_size)
203+
address_udt_transactions = address.ckb_udt_transactions(udt.id).order("block_timestamp desc nulls last, id desc").page(page).per(page_size)
204204

205205
valid_get api_v1_address_udt_transaction_url(address.address_hash, type_hash: udt.type_hash), params: { page: page, page_size: page_size }
206206
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: address_udt_transactions, page: page, page_size: page_size).call

test/controllers/api/v1/contracts_controller_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ class ContractsControllerTest < ActionDispatch::IntegrationTest
7777

7878
assert_equal response_json, response.body
7979
end
80+
81+
82+
test "should update dao contract cache when dao related data changed" do
83+
dao_contract = DaoContract.default_contract
84+
cache_version = dao_contract.cache_version
85+
dao_contract.touch
86+
assert_not_equal cache_version, dao_contract.reload.cache_version
87+
end
8088
end
8189
end
8290
end

0 commit comments

Comments
 (0)