Skip to content

Commit 3be0d53

Browse files
authored
Merge pull request #2637 from nervosnetwork/testnet
Deploy to mainnet
2 parents 8658868 + addcd11 commit 3be0d53

File tree

59 files changed

+174
-1319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+174
-1319
lines changed

app/controllers/api/v1/address_dao_transactions_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def show
1212
recent.page(@page).per(@page_size)
1313
json =
1414
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
15-
records_counter = RecordCounters::AddressDaoTransactions.new(address)
16-
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_dao_transactions, page: @page, page_size: @page_size, records_counter:).call
15+
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_dao_transactions, page: @page, page_size: @page_size).call
1716
CkbTransactionsSerializer.new(ckb_dao_transactions, options.merge(params: { previews: true })).serialized_json
1817
end
1918

app/controllers/api/v1/address_udt_transactions_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def show
1717
recent.page(@page).per(@page_size).fast_page
1818
json =
1919
Rails.cache.realize(ckb_udt_transactions.cache_key, version: ckb_udt_transactions.cache_version) do
20-
records_counter = RecordCounters::AddressUdtTransactions.new(address, udt.id)
21-
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_udt_transactions, page: @page, page_size: @page_size, records_counter:).call
20+
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_udt_transactions, page: @page, page_size: @page_size).call
2221
CkbTransactionsSerializer.new(ckb_udt_transactions, options.merge(params: { previews: true })).serialized_json
2322
end
2423

app/controllers/api/v1/block_transactions_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ def show
2121

2222
if stale?(ckb_transactions)
2323
expires_in 10.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
24-
records_counter = RecordCounters::BlockTransactions.new(ckb_transactions)
2524
ckb_transactions = ckb_transactions.page(@page).per(@page_size).fast_page
2625
options = FastJsonapi::PaginationMetaGenerator.new(
2726
request:,
2827
records: ckb_transactions,
2928
page: @page,
3029
page_size: @page_size,
31-
records_counter:,
3230
).call
3331
json = CkbTransactionsSerializer.new(ckb_transactions,
3432
options.merge(params: { previews: true })).serialized_json

app/controllers/api/v1/blocks_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def index
3131
head :not_found and return unless order_by.in? %w[number reward timestamp ckb_transactions_count]
3232

3333
blocks = blocks.order(order_by => asc_or_desc).order("number DESC").page(@page).per(@page_size)
34+
total_count = TableRecordCount.find_by(table_name: "blocks")&.count
3435

3536
json =
3637
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do
37-
records_counter = RecordCounters::Blocks.new
3838
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: blocks, page: @page,
39-
page_size: @page_size, records_counter: records_counter).call
39+
page_size: @page_size, total_count:).call
4040
BlockListSerializer.new(blocks, options).serialized_json
4141
end
4242
end

app/controllers/api/v1/ckb_transactions_controller.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ def index
4141

4242
ckb_transactions = ckb_transactions.order(order_by => asc_or_desc).
4343
page(@page).per(@page_size).fast_page
44-
44+
total_count = TableRecordCount.find_by(table_name: "ckb_transactions")&.count
4545
json =
4646
Rails.cache.realize(ckb_transactions.cache_key,
4747
version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do
48-
records_counter = RecordCounters::Transactions.new
4948
options = FastJsonapi::PaginationMetaGenerator.new(
5049
request:,
5150
records: ckb_transactions,
5251
page: @page,
5352
page_size: @page_size,
54-
records_counter:,
53+
total_count:,
5554
).call
5655
CkbTransactionListSerializer.new(ckb_transactions,
5756
options).serialized_json
@@ -70,17 +69,18 @@ def query
7069

7170
ckb_transactions =
7271
if @address
73-
records_counter = @tx_ids =
72+
@tx_ids =
7473
AccountBook.tx_committed.where(
7574
address_id: @address.id,
7675
).order(
7776
"block_number desc, tx_index desc",
7877
).select(
7978
"ckb_transaction_id",
8079
).page(@page).per(@page_size).fast_page
80+
total_count = @tx_ids.total_count
8181
CkbTransaction.where(id: @tx_ids.map(&:ckb_transaction_id)).order(block_number: :desc, tx_index: :desc)
8282
else
83-
records_counter = RecordCounters::Transactions.new
83+
total_count = TableRecordCount.find_by(table_name: "ckb_transactions")&.count
8484
CkbTransaction.recent.normal.page(@page).per(@page_size).fast_page
8585
end
8686
ckb_transactions = ckb_transactions.select(:id, :tx_hash, :block_id, :tags,
@@ -93,7 +93,7 @@ def query
9393
records: ckb_transactions,
9494
page: @page,
9595
page_size: @page_size,
96-
records_counter:,
96+
total_count: total_count,
9797
).call
9898
CkbTransactionsSerializer.new(ckb_transactions,
9999
options.merge(params: {

app/interactions/users/ckb_transactions.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def execute
1919

2020
options = FastJsonapi::PaginationMetaGenerator.new(
2121
records: transactions,
22-
records_counter: account_books,
2322
request:,
2423
page:,
2524
page_size:,
@@ -36,7 +35,7 @@ def filter_account_books
3635
address_ids = user.address_ids
3736
if address_hash.present?
3837
address = Address.find_address!(address_hash)
39-
address_ids = Array[address.id]
38+
address_ids = [address.id]
4039
end
4140

4241
scope = AccountBook.joins(:ckb_transaction).where(

app/lib/fast_jsonapi/pagination_meta_generator.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ class PaginationMetaGenerator
33
DEFAULT_PAGE = 1
44
DEFAULT_PER_PAGE = 20
55

6-
def initialize(request:, records:, page:, page_size:, total_pages: nil, records_counter: nil, total_count: nil)
6+
def initialize(request:, records:, page:, page_size:, total_pages: nil, total_count: nil)
77
@url = request.base_url + request.path + query_string(request.query_parameters)
88
@page = page.to_i
99
@page_size = limit_page_size(records, page_size.to_i)
1010
@records = records
11-
@records_counter = records_counter || records
12-
@total_count = total_count || @records_counter.total_count.to_i
11+
@total_count = total_count || records.total_count
1312
@total_pages = total_pages || calculated_total_pages
1413
@hash = { links: {}, meta: { total: @total_count, page_size: @page_size, total_pages: @total_pages } }
1514
end
@@ -24,7 +23,7 @@ def call
2423

2524
private
2625

27-
attr_reader :page, :page_size, :records, :records_counter, :total_count
26+
attr_reader :page, :page_size, :records, :total_count
2827
attr_accessor :url, :hash
2928

3029
def current_page

app/models/block.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class Block < ApplicationRecord
1919

2020
# the `ckb_transactions` is only available when the block is included in chain
2121
has_many :ckb_transactions
22-
has_many :block_transactions
23-
# the transactions included in the block no matter if the block is included in chain
24-
has_many :contained_transactions, class_name: "CkbTransaction",
25-
through: :block_transactions,
26-
inverse_of: :included_blocks
2722
has_many :uncle_blocks
2823
has_many :cell_outputs
2924
has_many :cell_inputs

app/models/block_propagation_delay.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/models/block_time_statistic.rb

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)