Skip to content

Commit 6962ab9

Browse files
authored
Merge pull request #2806 from nervosnetwork/develop
Deploy to testnet
2 parents babea68 + 494fde4 commit 6962ab9

15 files changed

+37
-36
lines changed

app/controllers/api/v1/address_dao_transactions_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def show
1616
# .select(select_fields + ["COUNT(cell_inputs.id) AS cell_inputs_count", "COUNT(cell_outputs.id) AS cell_outputs_count"])
1717
.select(select_fields)
1818
.recent.page(@page).per(@page_size)
19+
1920
json =
20-
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
21+
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version, expires_in: 1.hours) do
2122
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_dao_transactions, page: @page, page_size: @page_size).call
2223
CkbTransactionsSerializer.new(ckb_dao_transactions, options.merge(params: { previews: true })).serialized_json
2324
end

app/controllers/api/v1/address_udt_transactions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def show
2121
.select(select_fields)
2222
.recent.page(@page).per(@page_size).fast_page
2323
json =
24-
Rails.cache.realize(ckb_udt_transactions.cache_key, version: ckb_udt_transactions.cache_version) do
24+
Rails.cache.realize(ckb_udt_transactions.cache_key, version: ckb_udt_transactions.cache_version, expires_in: 1.hours) do
2525
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_udt_transactions, page: @page, page_size: @page_size).call
2626
CkbTransactionsSerializer.new(ckb_udt_transactions, options.merge(params: { previews: true })).serialized_json
2727
end

app/controllers/api/v1/blocks_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index
99
blocks = Block.recent.select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count,
1010
:live_cell_changes, :updated_at).limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i)
1111
json =
12-
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do
12+
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds, expires_in: 2.minutes) do
1313
BlockListSerializer.new(blocks).serialized_json
1414
end
1515
else
@@ -34,7 +34,7 @@ def index
3434
total_count = TableRecordCount.find_by(table_name: "blocks")&.count
3535

3636
json =
37-
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do
37+
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds, expires_in: 10.minutes) do
3838
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: blocks, page: @page,
3939
page_size: @page_size, total_count:).call
4040
BlockListSerializer.new(blocks, options).serialized_json

app/controllers/api/v1/ckb_transactions_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def index
1212
).limit((Settings.homepage_transactions_records_count || 15).to_i)
1313
json =
1414
Rails.cache.realize(ckb_transactions.cache_key,
15-
version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do
15+
version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds, expires_in: 2.minutes) do
1616
CkbTransactionListSerializer.new(ckb_transactions).serialized_json
1717
end
1818
render json:
@@ -44,7 +44,7 @@ def index
4444
total_count = TableRecordCount.find_by(table_name: "ckb_transactions")&.count
4545
json =
4646
Rails.cache.realize(ckb_transactions.cache_key,
47-
version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do
47+
version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds, expires_in: 10.minutes) do
4848
options = FastJsonapi::PaginationMetaGenerator.new(
4949
request:,
5050
records: ckb_transactions,
@@ -87,7 +87,7 @@ def query
8787
:block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at)
8888
json =
8989
Rails.cache.realize(ckb_transactions.cache_key,
90-
version: ckb_transactions.cache_version, race_condition_ttl: 1.minute) do
90+
version: ckb_transactions.cache_version, race_condition_ttl: 1.minute, expires_in: 10.minutes) do
9191
options = FastJsonapi::PaginationMetaGenerator.new(
9292
request:,
9393
records: ckb_transactions,

app/controllers/api/v1/contracts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def show
66

77
dao_contract = DaoContract.default_contract
88
json =
9-
Rails.cache.realize(dao_contract.cache_key, version: dao_contract.cache_version, race_condition_ttl: 3.seconds) do
9+
Rails.cache.realize(dao_contract.cache_key, version: dao_contract.cache_version, race_condition_ttl: 3.seconds, expires_in: 5.minutes) do
1010
DaoContractSerializer.new(dao_contract).serialized_json
1111
end
1212

app/controllers/api/v1/daily_statistics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def show
1515

1616
def rendered_json(daily_statistics)
1717
Rails.cache.realize("#{daily_statistics.cache_key}/#{params[:id]}", version: daily_statistics.cache_version,
18-
race_condition_ttl: 3.seconds) do
18+
race_condition_ttl: 3.seconds, expires_in: 1.day) do
1919
case params[:id]
2020
when "avg_hash_rate"
2121
DailyStatisticSerializer.new(daily_statistics.presence || [], { params: { indicator: params[:id] } })

app/models/block.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def self.last_7_days_ckb_node_version
9595
# @param block_hash [String] block hash
9696
# @return [Hash] raw hash of the block
9797
def self.fetch_raw_hash_with_cycles(block_hash)
98-
Rails.cache.fetch(["Block", block_hash, "raw_hash_with_cycles"], expires_in: 1.day) do
98+
Rails.cache.fetch(["Block", block_hash, "raw_hash_with_cycles"], expires_in: 10.minutes) do
9999
res = CkbSync::Api.instance.directly_single_call_rpc method: "get_block", params: [block_hash, "0x2", true]
100100

101101
r = res["result"].with_indifferent_access
@@ -133,7 +133,7 @@ def self.fetch_raw_hash_with_cycles_by_number(number)
133133
r = res["result"].with_indifferent_access
134134
# because the chain may reorg sometimes
135135
# so we can only store cache against block hash
136-
Rails.cache.write(["Block", r["block"]["header"]["hash"], "raw_hash"], r["block"], expires_in: 1.day)
136+
Rails.cache.write(["Block", r["block"]["header"]["hash"], "raw_hash"], r["block"], expires_in: 10.minutes)
137137
# store transaction hash directly to cache ahead
138138
r["block"]["transactions"].each do |tx|
139139
CkbTransaction.write_raw_hash_cache tx["hash"], tx
@@ -165,7 +165,7 @@ def raw_hash
165165
# @return [CKB::Types::Block]
166166
def sdk_block
167167
@sdk_block ||=
168-
Rails.cache.fetch(["Block", block_hash, "object"], expires_in: 1.hour) do
168+
Rails.cache.fetch(["Block", block_hash, "object"], expires_in: 10.minutes) do
169169
CKB::Types::Block.from_h(original_raw_hash)
170170
end
171171
end
@@ -238,7 +238,7 @@ def self.cached_find(query_key)
238238
where(number: query_key).first
239239
end
240240
if block.present?
241-
Rails.cache.fetch([name, query_key], race_condition_ttl: 3.seconds, expires_in: 30.minutes) do
241+
Rails.cache.fetch([name, query_key], race_condition_ttl: 3.seconds, expires_in: 10.minutes) do
242242
BlockSerializer.new(block)
243243
end
244244
end
@@ -249,7 +249,7 @@ def self.cached_find(query_key)
249249
# @param epoch_number [Integer]
250250
# @return [Hash] {number: block_number, bytes: block_size}
251251
def self.largest_in_epoch(epoch_number)
252-
Rails.cache.fetch([:epoch, epoch_number, :largest_block]) do
252+
Rails.cache.fetch([:epoch, epoch_number, :largest_block], expires_in: 12.hour) do
253253
b = Block.where(epoch: epoch_number).order(block_size: :desc).first
254254
if b&.block_size
255255
{

app/models/cell_output.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def dao
155155
def self.find_by_pointer(tx_hash, index)
156156
Rails.cache.fetch(["cell_output", tx_hash, index], skip_nil: true,
157157
race_condition_ttl: 10.seconds,
158-
expires_in: 1.day) do
158+
expires_in: 1.hour) do
159159
tx_id = CkbTransaction.tx_committed.find_by_tx_hash(tx_hash)&.id
160160
Rails.logger.info("find_by_pointer: tx_hash: #{tx_hash}, index: #{index}, tx_id: #{tx_id}")
161161
if tx_id

app/models/ckb_transaction.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class CkbTransaction < ApplicationRecord
5252
after_commit :flush_cache
5353

5454
def self.cached_find(query_key)
55-
Rails.cache.realize([name, query_key], race_condition_ttl: 3.seconds) do
55+
Rails.cache.realize([name, query_key], race_condition_ttl: 3.seconds, expires_in: 1.hour) do
5656
find_by(tx_hash: query_key)
5757
end
5858
end
5959

6060
def self.largest_in_epoch(epoch_number)
61-
Rails.cache.fetch(["epoch", epoch_number, "largest_tx"]) do
61+
Rails.cache.fetch(["epoch", epoch_number, "largest_tx"], expires_in: 12.hour) do
6262
tx = CkbTransaction.where(block: { epoch_number: }).order(bytes: :desc).first
6363
if tx.bytes
6464
{
@@ -77,7 +77,7 @@ def self.write_raw_hash_cache(tx_hash, raw_hash = nil)
7777
raw_hash = tx_hash
7878
tx_hash = raw_hash["hash"]
7979
end
80-
Rails.cache.write([name, tx_hash, "raw_hash"], raw_hash, expires_in: 1.day)
80+
Rails.cache.write([name, tx_hash, "raw_hash"], raw_hash, expires_in: 10.minutes)
8181
end
8282

8383
# fetch using rpc method "get_transaction"
@@ -86,7 +86,7 @@ def self.write_raw_hash_cache(tx_hash, raw_hash = nil)
8686
# @param write_raw_hash_cache [Boolean] if we should write raw hash of transaction without status to cache
8787
# @return [Hash]
8888
def self.fetch_raw_hash_with_status(tx_hash, write_raw_hash_cache: true)
89-
Rails.cache.fetch([name, tx_hash, "raw_hash_with_status"], expires_in: 1.day, skip_nil: true) do
89+
Rails.cache.fetch([name, tx_hash, "raw_hash_with_status"], expires_in: 10.minutes, skip_nil: true) do
9090
res = CkbSync::Api.instance.directly_single_call_rpc method: "get_transaction", params: [tx_hash]
9191
h = res["result"].with_indifferent_access
9292
self.write_raw_hash_cache(tx_hash, h["transaction"]) if write_raw_hash_cache
@@ -99,7 +99,7 @@ def self.fetch_raw_hash_with_status(tx_hash, write_raw_hash_cache: true)
9999
# @param tx_hash [String]
100100
# @return [Hash]
101101
def self.fetch_raw_hash(tx_hash)
102-
Rails.cache.fetch([name, tx_hash, "raw_hash"], expires_in: 1.day, skip_nil: true) do
102+
Rails.cache.fetch([name, tx_hash, "raw_hash"], expires_in: 10.minutes, skip_nil: true) do
103103
fetch_raw_hash_with_status(tx_hash, write_raw_hash_cache: false)["transaction"]
104104
end
105105
end
@@ -108,9 +108,9 @@ def self.fetch_raw_hash(tx_hash)
108108
# @param tx_hash [String]
109109
# @return [CKB::Types::TransactionWithStatus]
110110
def self.fetch_sdk_transaction_with_status(tx_hash, write_object_cache: true)
111-
Rails.cache.fetch([name, tx_hash, "object_with_status"], expires_in: 1.day, skip_nil: true) do
111+
Rails.cache.fetch([name, tx_hash, "object_with_status"], expires_in: 10.minutes, skip_nil: true) do
112112
tx = CKB::Types::TransactionWithStatus.from_h fetch_raw_hash_with_status(tx_hash)
113-
Rails.cache.write([name, tx_hash, "object"], tx.transaction, expires_in: 1.day) if write_object_cache
113+
Rails.cache.write([name, tx_hash, "object"], tx.transaction, expires_in: 10.minutes) if write_object_cache
114114
tx
115115
end
116116
end
@@ -119,13 +119,13 @@ def self.fetch_sdk_transaction_with_status(tx_hash, write_object_cache: true)
119119
# @param tx_hash [String]
120120
# @return [CKB::Types::Transaction]
121121
def self.fetch_sdk_transaction(tx_hash)
122-
Rails.cache.fetch([name, tx_hash, "object"], expires_in: 1.day, skip_nil: true) do
122+
Rails.cache.fetch([name, tx_hash, "object"], expires_in: 10.minutes, skip_nil: true) do
123123
sdk_tx_with_status = Rails.cache.read([name, tx_hash, "object_with_status"])
124124
if sdk_tx_with_status
125125
return sdk_transaction_with_status.transaction
126126
else
127127
tx = CKB::Types::Transaction.from_h fetch_raw_hash(tx_hash).with_indifferent_access
128-
Rails.cache.write([name, tx_hash, "object"], tx, expires_in: 1.day)
128+
Rails.cache.write([name, tx_hash, "object"], tx, expires_in: 10.minutes)
129129
tx
130130
end
131131
end
@@ -199,7 +199,7 @@ def detailed_message
199199

200200
# convert current record to raw hash with standard RPC json data structure
201201
def to_raw
202-
Rails.cache.fetch([self.class.name, tx_hash, "raw_hash"], expires_in: 1.day) do
202+
Rails.cache.fetch([self.class.name, tx_hash, "raw_hash"], expires_in: 10.minutes) do
203203
_outputs = cell_outputs.order(cell_index: :asc).to_a
204204
cell_deps = cell_dependencies.includes(:cell_output).to_a
205205

app/models/monetary_data.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def id
1212
end
1313

1414
def nominal_apc(max_year = 20)
15-
Rails.cache.realize("nominal_apc#{max_year}") do
15+
Rails.cache.realize("nominal_apc#{max_year}", expires_in: 1.day) do
1616
total_supplies_per_year(max_year).each_with_index.map do |_, index|
1717
cumulative_total_supply =
1818
if index.zero?
@@ -29,7 +29,7 @@ def nominal_apc(max_year = 20)
2929
end
3030

3131
def nominal_inflation_rate(max_year = 50)
32-
Rails.cache.realize("nominal_inflation_rate#{max_year}") do
32+
Rails.cache.realize("nominal_inflation_rate#{max_year}", expires_in: 1.day) do
3333
secondary_issuance_monthly = SECONDARY_SUPPLY_PER_YEAR / 12
3434
rs =
3535
total_supplies_per_year(max_year).each_with_index.map do |_, index|
@@ -51,7 +51,7 @@ def nominal_inflation_rate(max_year = 50)
5151
end
5252

5353
def real_inflation_rate(max_year = 50)
54-
Rails.cache.realize("real_inflation#{max_year}") do
54+
Rails.cache.realize("real_inflation#{max_year}", expires_in: 1.day) do
5555
nominal_inflation_rate(max_year).
5656
zip(nominal_apc(max_year)).
5757
map { |item| item.reduce(:-).truncate(8) }

0 commit comments

Comments
 (0)