Skip to content

Commit 313c38e

Browse files
authored
Merge pull request #696 from nervosnetwork/rc/v0.10.1
2 parents 29df590 + 21f451c commit 313c38e

35 files changed

+205
-140
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# [v0.10.1](https://github.com/shaojunda/ckb-explorer/compare/v0.10.0...v0.10.1) (2020-07-17)
2+
3+
4+
### Bug Fixes
5+
6+
* [#695](https://github.com/nervosnetwork/ckb-explorer/pull/695): fix average block time missing data
7+
8+
9+
### Performance Improvements
10+
11+
* [#683](https://github.com/nervosnetwork/ckb-explorer/pull/683): perf lock info
12+
* [#687](https://github.com/nervosnetwork/ckb-explorer/pull/687): perf use DB data replace RPC call
13+
* [#688](https://github.com/nervosnetwork/ckb-explorer/pull/688): perf transaction index
14+
* [#691](https://github.com/nervosnetwork/ckb-explorer/pull/691): perf address unclaimed compensation worker
15+
* [#692](https://github.com/nervosnetwork/ckb-explorer/pull/692): perf add cache on lock_script
16+
* [#693](https://github.com/nervosnetwork/ckb-explorer/pull/693): perf use cache on blocks controller
17+
* [#694](https://github.com/nervosnetwork/ckb-explorer/pull/694): perf contract show
18+
19+
120
# [v0.10.0](https://github.com/nervosnetwork/ckb-explorer/compare/v0.9.9...v0.10.0) (2020-07-10)
221

322

Gemfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ gem "rails", "~> 6.0.0"
88
# Use postgresql as the database for Active Record
99
gem "pg", ">= 0.18", "< 2.0"
1010
# Use Puma as the app server
11-
gem "puma", "~> 4.3.5"
11+
gem "puma", "~> 4.3.5", require: false
1212
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
1313
# gem 'jbuilder', '~> 2.5'
1414
# Use Redis adapter to run Action Cable in production
@@ -34,9 +34,6 @@ gem "dotenv-rails"
3434
# manage environment specific settings by config
3535
gem "config"
3636

37-
# daemons
38-
gem "daemons", "~> 1.2", ">= 1.2.6"
39-
4037
# CKB SDK
4138
gem "ckb-sdk-ruby", git: "https://github.com/nervosnetwork/ckb-sdk-ruby.git", require: "ckb", branch: "develop"
4239

@@ -64,12 +61,14 @@ gem "kaminari"
6461

6562
gem "ruby-progressbar", require: false
6663

67-
gem "sentry-raven"
64+
group :production do
65+
gem "sentry-raven"
66+
gem "newrelic_rpm"
67+
end
6868

6969
# Deployment
7070
gem "mina", require: false
7171
gem "mina-multistage", require: false
72-
gem "newrelic_rpm"
7372
gem "rack-attack"
7473

7574
group :development, :test do
@@ -88,7 +87,7 @@ group :test do
8887
gem "database_cleaner"
8988
gem "mocha"
9089
gem "factory_bot_rails"
91-
gem "faker", git: "https://github.com/stympy/faker.git", branch: "master"
90+
gem "faker", git: "https://github.com/faker-ruby/faker.git", branch: "master"
9291
gem "codecov", require: false
9392
end
9493

@@ -100,7 +99,7 @@ group :development do
10099
gem "rubocop", require: false
101100
gem "rubocop-rails", require: false
102101
gem "rubocop-performance", require: false
103-
gem "awesome_print"
102+
gem "awesome_print", require: false
104103
gem "annotate"
105104
end
106105

Gemfile.lock

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
GIT
2+
remote: https://github.com/faker-ruby/faker.git
3+
revision: 484f776b9e734eea24114f2c46d9dad9622f0f4f
4+
branch: master
5+
specs:
6+
faker (2.13.0)
7+
i18n (>= 1.6, < 2)
8+
19
GIT
210
remote: https://github.com/nervosnetwork/ckb-sdk-ruby.git
311
revision: c9e651c25953c0c6173f8c1fa75e98e546f1164b
@@ -8,19 +16,6 @@ GIT
816
net-http-persistent (~> 3.1.0)
917
rbnacl (~> 7.1.1)
1018

11-
GIT
12-
remote: https://github.com/stympy/faker.git
13-
revision: 0e8cc7eeb160532c84d8665aef649788e48a2c9c
14-
branch: master
15-
specs:
16-
faker (1.9.3)
17-
i18n (>= 0.7)
18-
pastel (~> 0.7.2)
19-
thor (~> 0.20.0)
20-
tty-pager (~> 0.12.0)
21-
tty-screen (~> 0.6.5)
22-
tty-tree (~> 0.3.0)
23-
2419
GEM
2520
remote: https://rubygems.org/
2621
specs:
@@ -91,7 +86,7 @@ GEM
9186
awesome_print (1.8.0)
9287
bitcoin-secp256k1 (0.5.2)
9388
ffi (>= 1.9.25)
94-
bootsnap (1.4.4)
89+
bootsnap (1.4.6)
9590
msgpack (~> 1.0)
9691
builder (3.2.4)
9792
chronic_duration (0.10.6)
@@ -110,7 +105,6 @@ GEM
110105
crack (0.4.3)
111106
safe_yaml (~> 1.0.0)
112107
crass (1.0.6)
113-
daemons (1.3.1)
114108
database_cleaner (1.7.0)
115109
deep_merge (1.2.1)
116110
docile (1.3.2)
@@ -146,7 +140,6 @@ GEM
146140
dry-equalizer (~> 0.2)
147141
dry-logic (~> 0.5, >= 0.5.0)
148142
dry-types (~> 0.14.0)
149-
equatable (0.5.0)
150143
erubi (1.9.0)
151144
et-orbi (1.2.2)
152145
tzinfo
@@ -212,7 +205,7 @@ GEM
212205
ruby-progressbar
213206
mocha (1.8.0)
214207
metaclass (~> 0.0.1)
215-
msgpack (1.2.10)
208+
msgpack (1.3.3)
216209
multipart-post (2.1.1)
217210
net-http-persistent (3.1.0)
218211
connection_pool (~> 2.2)
@@ -225,9 +218,6 @@ GEM
225218
parallel (1.17.0)
226219
parser (2.6.3.0)
227220
ast (~> 2.4.0)
228-
pastel (0.7.2)
229-
equatable (~> 0.5.0)
230-
tty-color (~> 0.4.0)
231221
pg (1.1.4)
232222
pry (0.12.2)
233223
coderay (~> 1.1.0)
@@ -338,26 +328,12 @@ GEM
338328
actionpack (>= 4.0)
339329
activesupport (>= 4.0)
340330
sprockets (>= 3.0.0)
341-
strings (0.1.5)
342-
strings-ansi (~> 0.1)
343-
unicode-display_width (~> 1.5)
344-
unicode_utils (~> 1.4)
345-
strings-ansi (0.1.0)
346331
thor (0.20.3)
347332
thread_safe (0.3.6)
348333
tilt (2.0.9)
349-
tty-color (0.4.3)
350-
tty-pager (0.12.1)
351-
strings (~> 0.1.4)
352-
tty-screen (~> 0.6)
353-
tty-which (~> 0.4)
354-
tty-screen (0.6.5)
355-
tty-tree (0.3.0)
356-
tty-which (0.4.1)
357334
tzinfo (1.2.7)
358335
thread_safe (~> 0.1)
359336
unicode-display_width (1.6.0)
360-
unicode_utils (1.4.0)
361337
url (0.3.2)
362338
vcr (5.0.0)
363339
webmock (3.6.0)
@@ -380,7 +356,6 @@ DEPENDENCIES
380356
ckb-sdk-ruby!
381357
codecov
382358
config
383-
daemons (~> 1.2, >= 1.2.6)
384359
database_cleaner
385360
dotenv-rails
386361
factory_bot_rails

app/controllers/api/v1/blocks_controller.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ class BlocksController < ApplicationController
66

77
def index
88
if from_home_page?
9-
block_timestamps = Block.recent.limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i).pluck(:timestamp)
10-
blocks = Block.where(timestamp: block_timestamps).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes).recent
11-
options = {}
9+
blocks = Block.recent.limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes)
10+
json =
11+
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do
12+
BlockListSerializer.new(blocks).serialized_json
13+
end
1214
else
13-
block_timestamps = Block.recent.select(:timestamp).page(@page).per(@page_size)
14-
blocks = Block.where(timestamp: block_timestamps.pluck(:timestamp)).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes).recent
15-
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: block_timestamps, page: @page, page_size: @page_size).call
15+
blocks = Block.recent.select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes).page(@page).per(@page_size)
16+
json =
17+
Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do
18+
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: blocks, page: @page, page_size: @page_size).call
19+
BlockListSerializer.new(blocks, options).serialized_json
20+
end
1621
end
1722

18-
render json: BlockListSerializer.new(blocks, options)
23+
render json: json
1924
end
2025

2126
def show

app/controllers/api/v1/ckb_transactions_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ def index
88
if from_home_page?
99
ckb_transactions = CkbTransaction.recent.normal.limit(ENV["HOMEPAGE_TRANSACTIONS_RECORDS_COUNT"].to_i).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved)
1010
json =
11-
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do
11+
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do
1212
CkbTransactionListSerializer.new(ckb_transactions).serialized_json
1313
end
1414
render json: json
1515
else
1616
ckb_transactions = CkbTransaction.recent.normal.page(@page).per(@page_size).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved)
1717
json =
18-
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do
18+
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do
1919
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
2020
CkbTransactionListSerializer.new(ckb_transactions, options).serialized_json
2121
end

app/controllers/api/v1/contracts_controller.rb

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

7-
render json: DaoContractSerializer.new(DaoContract.default_contract)
7+
dao_contract = DaoContract.where(id: 1)
8+
json =
9+
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
11+
end
12+
13+
render json: json
814
end
915
end
1016
end

app/controllers/api/v1/dao_depositors_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Api
22
module V1
33
class DaoDepositorsController < ApplicationController
44
def index
5-
addresses = Address.select(:id, :address_hash, :dao_deposit, :average_deposit_time).where("dao_deposit > 0").order(dao_deposit: :desc).limit(100)
5+
addresses = Address.select(:id, :address_hash, :dao_deposit, :average_deposit_time).where(is_depositor: true).order(dao_deposit: :desc).limit(100)
66

77
render json: DaoDepositorSerializer.new(addresses)
88
end

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def catch_404
1717
private
1818

1919
def set_raven_context
20-
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
20+
Raven.extra_context(params: params.to_unsafe_h, url: request.url) if Rails.env.production?
2121
end
2222

2323
def api_error(error)

app/models/address.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def lock_info
6565
end
6666

6767
def lock_script
68-
LockScript.where(address: self).first
68+
Rails.cache.realize(["Address", "lock_script", id], race_condition_ttl: 3.seconds) do
69+
LockScript.where(address: self).first
70+
end
6971
end
7072

7173
def self.find_or_create_address(lock_script, block_timestamp)
@@ -133,10 +135,7 @@ def phase1_dao_interests
133135
def unmade_dao_interests
134136
tip_dao = Block.recent.first.dao
135137
cell_outputs.nervos_dao_deposit.live.find_each.reduce(0) do |memo, cell_output|
136-
dao = cell_output.block.dao
137-
parse_dao = CkbUtils.parse_dao(dao)
138-
tip_parse_dao = CkbUtils.parse_dao(tip_dao)
139-
memo + (cell_output.capacity - cell_output.occupied_capacity).to_i * tip_parse_dao.ar_i / parse_dao.ar_i - (cell_output.capacity - cell_output.occupied_capacity)
138+
memo + DaoCompensationCalculator.new(cell_output, tip_dao).call
140139
end
141140
end
142141
end

app/models/cell_output.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def flush_cache
8585
# consumed_block_timestamp :decimal(30, )
8686
# type_hash :string
8787
# udt_amount :decimal(40, )
88+
# dao :string
8889
#
8990
# Indexes
9091
#

0 commit comments

Comments
 (0)