Skip to content

Commit 1e8373f

Browse files
authored
Merge pull request #684 from nervosnetwork/rc/v0.9.9
2 parents 3b259e5 + 47e7bde commit 1e8373f

File tree

9 files changed

+142
-3
lines changed

9 files changed

+142
-3
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# [v0.9.9](https://github.com/nervosnetwork/ckb-explorer/compare/v0.9.8...v0.9.9) (2020-07-09)
2+
3+
4+
### Bug Fixes
5+
6+
* [#669](https://github.com/nervosnetwork/ckb-explorer/pull/669): fix ActiveRecord::IrreversibleOrderError
7+
8+
9+
### Features
10+
11+
* [#677](https://github.com/nervosnetwork/ckb-explorer/pull/677): update dao compensation logic to include the unclaimed compensation
12+
* [#680](https://github.com/nervosnetwork/ckb-explorer/pull/680): add maintenance info API
13+
* [#682](https://github.com/nervosnetwork/ckb-explorer/pull/682): add flush front-end cache API
14+
15+
### Performance Improvements
16+
17+
* [#699](https://github.com/nervosnetwork/ckb-explorer/pull/669): use separate query and just select needed field
18+
* [#670](https://github.com/nervosnetwork/ckb-explorer/pull/670): use recent scope on block query
19+
* [#675](https://github.com/nervosnetwork/ckb-explorer/pull/675): add cache on blockchain info
20+
121
# [v0.9.8](https://github.com/nervosnetwork/ckb-explorer/compare/v0.9.7...v0.9.8) (2020-06-29)
222

323

app/controllers/api/v1/daily_statistics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class DailyStatisticsController < ApplicationController
44
before_action :validate_query_params, only: :show
55

66
def show
7-
daily_statistics = DailyStatistic.order(:created_at_unixtimestamp).limit(365)
7+
daily_statistics = DailyStatistic.order(:created_at_unixtimestamp)
88
render json: DailyStatisticSerializer.new(daily_statistics, { params: { indicator: params[:id] } })
99
end
1010

app/models/statistic_info.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def blockchain_info
8181
end
8282
end
8383

84+
def maintenance_info
85+
Rails.cache.fetch("maintenance_info")
86+
end
87+
88+
def flush_cache_info
89+
Rails.cache.realize("flush_cache_info") || []
90+
end
91+
8492
private
8593

8694
attr_reader :hash_rate_statistical_interval, :average_block_time_interval

app/serializers/statistic_serializer.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ class StatisticSerializer
2525
params && params[:info_name] == "blockchain_info"
2626
}
2727

28+
attribute :flush_cache_info, if: Proc.new { |_record, params|
29+
params && params[:info_name] == "flush_cache_info"
30+
}
31+
2832
attribute :address_balance_ranking, if: Proc.new { |_record, params|
2933
params && params[:info_name] == "address_balance_ranking"
3034
}
35+
36+
attribute :maintenance_info, if: Proc.new { |_record, params|
37+
params && params[:info_name] == "maintenance_info"
38+
}
3139
end

doc/api.raml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,30 @@ types:
540540
"hash_rate": {
541541
type: "string",
542542
},
543+
"flush_cache_info": {
544+
type: "string[]"
545+
}
543546
"blockchain_info": {
544547
type: "object"
545548
},
546549
"address_balance_ranking": {
547550
type: "address_balance_ranking"
548551
}
552+
"maintenance_info": {
553+
type: "maintenance_info"
554+
}
555+
}
556+
}
557+
558+
maintenance_info: {
559+
type: object,
560+
properties: {
561+
"stat_at": {
562+
type: "string"
563+
},
564+
"end_at": {
565+
type: "string"
566+
}
549567
}
550568
}
551569

@@ -2414,6 +2432,19 @@ types:
24142432
}
24152433
}
24162434
}
2435+
flush_cache_info: |
2436+
{
2437+
"data": {
2438+
"id": "1594109792",
2439+
"type": "statistic",
2440+
"attributes": {
2441+
"flush_cache_info": [
2442+
"liquidity",
2443+
"deposit_compensation"
2444+
]
2445+
}
2446+
}
2447+
}
24172448
address_balance_ranking: |
24182449
{
24192450
"data": {
@@ -2475,6 +2506,19 @@ types:
24752506
}
24762507
}
24772508
}
2509+
maintenance_info: |
2510+
{
2511+
"data": {
2512+
"id": "1594105429",
2513+
"type": "statistic",
2514+
"attributes": {
2515+
"maintenance_info": {
2516+
"start_at": "1591632000",
2517+
"end_at": "1591639200"
2518+
}
2519+
}
2520+
}
2521+
}
24782522
404:
24792523
body:
24802524
application/vnd.api+json:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
desc "Usage: RAILS_ENV=production bundle exec rake 'set_flush_cache_info[liquidity deposit_compensation, true]'"
2+
task :set_flush_cache_info, [:indicators, :dry_run] => :environment do |_, args|
3+
raise "please input indicators" if args[:indicators].blank?
4+
binding.pry
5+
6+
indicators = args[:indicators].split(" ")
7+
dry_run = args[:dry_run] || "true"
8+
if dry_run == "true"
9+
puts "indicators: #{indicators.join(", ")}"
10+
else
11+
Rails.cache.write("flush_cache_info", indicators, expires_in: 1.day)
12+
puts "done"
13+
end
14+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
desc "Usage: RAILS_ENV=production bundle exec rake 'set_maintenance_info[2020-06-09 00:00:00, nil]'"
2+
task :set_maintenance_info, [:start_at, :end_at, :dry_run] => :environment do |_, args|
3+
raise "please input start at" if args[:start_at].blank?
4+
5+
start_at = Time.parse(args[:start_at]).utc
6+
dry_run = args[:dry_run] || "true"
7+
if args[:end_at] != "nil"
8+
end_at = Time.parse(args[:end_at]).utc
9+
else
10+
end_at = start_at + 2.hours
11+
end
12+
if dry_run == "true"
13+
puts "start_at: #{start_at}"
14+
puts "end_at: #{end_at}"
15+
else
16+
info = { start_at: start_at.to_i.to_s, end_at: end_at.to_i.to_s }
17+
puts "inf: #{info}"
18+
Rails.cache.write("maintenance_info", info)
19+
end
20+
end

public/api_doc.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
}
10841084
]
10851085
}
1086-
</code></pre></div></div></div></div></div></div></div></div><div class="panel panel-white resource-modal"><div class="panel-heading"><h4 class="panel-title"><a class="collapsed" data-toggle="collapse" href="#panel_statistics__info_name_"><span class="parent">/statistics</span>/{info_name}</a> <span class="methods"><a href="#statistics__info_name__get"><span class="badge badge_get">get</span></a></span></h4></div><div id="panel_statistics__info_name_" class="panel-collapse collapse"><div class="panel-body"><div class="list-group"><div onclick="window.location.href = '#statistics__info_name__get'" class="list-group-item"><span class="badge badge_get">get</span><div class="method_description"><p>Returns the specific statistic info</p></div><div class="clearfix"></div></div></div></div></div><div class="modal fade" tabindex="0" id="statistics__info_name__get"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="myModalLabel"><span class="badge badge_get">get</span> <span class="parent">/statistics</span>/{info_name}</h4></div><div class="modal-body"><div class="alert alert-info"><p>Returns the specific statistic info</p></div><ul class="nav nav-tabs"><li class="active"><a href="#statistics__info_name__get_request" data-toggle="tab">Request</a></li><li><a href="#statistics__info_name__get_response" data-toggle="tab">Response</a></li></ul><div class="tab-content"><div class="tab-pane active" id="statistics__info_name__get_request"><h3>URI Parameters</h3><ul><li><strong>info_name</strong>: <em><span class="required">required</span>(string)</em><p>The statistic info name</p></li></ul></div><div class="tab-pane" id="statistics__info_name__get_response"><h2>HTTP status code <a href="http://httpstatus.es/200" target="_blank">200</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>data</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>tip_block_number</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>average_block_time</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>current_epoch_difficulty</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>hash_rate</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>blockchain_info</strong>: <em><span class="required">required</span>(object)</em><ul></ul></li><li><strong>address_balance_ranking</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>ranking</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>address</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>balance</strong>: <em><span class="required">required</span>(string)</em></li></ul></li></ul></li></ul><p><strong>Examples</strong>:</p><div class="examples"><p><strong>tip_block_number</strong>:<br></p><pre><code>{
1086+
</code></pre></div></div></div></div></div></div></div></div><div class="panel panel-white resource-modal"><div class="panel-heading"><h4 class="panel-title"><a class="collapsed" data-toggle="collapse" href="#panel_statistics__info_name_"><span class="parent">/statistics</span>/{info_name}</a> <span class="methods"><a href="#statistics__info_name__get"><span class="badge badge_get">get</span></a></span></h4></div><div id="panel_statistics__info_name_" class="panel-collapse collapse"><div class="panel-body"><div class="list-group"><div onclick="window.location.href = '#statistics__info_name__get'" class="list-group-item"><span class="badge badge_get">get</span><div class="method_description"><p>Returns the specific statistic info</p></div><div class="clearfix"></div></div></div></div></div><div class="modal fade" tabindex="0" id="statistics__info_name__get"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="myModalLabel"><span class="badge badge_get">get</span> <span class="parent">/statistics</span>/{info_name}</h4></div><div class="modal-body"><div class="alert alert-info"><p>Returns the specific statistic info</p></div><ul class="nav nav-tabs"><li class="active"><a href="#statistics__info_name__get_request" data-toggle="tab">Request</a></li><li><a href="#statistics__info_name__get_response" data-toggle="tab">Response</a></li></ul><div class="tab-content"><div class="tab-pane active" id="statistics__info_name__get_request"><h3>URI Parameters</h3><ul><li><strong>info_name</strong>: <em><span class="required">required</span>(string)</em><p>The statistic info name</p></li></ul></div><div class="tab-pane" id="statistics__info_name__get_response"><h2>HTTP status code <a href="http://httpstatus.es/200" target="_blank">200</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>data</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>tip_block_number</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>average_block_time</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>current_epoch_difficulty</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>hash_rate</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>flush_cache_info</strong>: <em><span class="required">required</span>(array of string)</em></li><li><strong>blockchain_info"</strong>: <em><span class="required">required</span>(object)</em><ul></ul></li><li><strong>address_balance_ranking</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>ranking</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>address</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>balance</strong>: <em><span class="required">required</span>(string)</em></li></ul></li><li><strong>maintenance_info"</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>stat_at</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>end_at</strong>: <em><span class="required">required</span>(string)</em></li></ul></li></ul></li></ul><p><strong>Examples</strong>:</p><div class="examples"><p><strong>tip_block_number</strong>:<br></p><pre><code>{
10871087
"data": {
10881088
"id": "1",
10891089
"type": "statistic_info",
@@ -1148,6 +1148,18 @@
11481148
}
11491149
}
11501150
}
1151+
</code></pre><p><strong>flush_cache_info</strong>:<br></p><pre><code>{
1152+
"data": {
1153+
"id": "1594109792",
1154+
"type": "statistic",
1155+
"attributes": {
1156+
"flush_cache_info": [
1157+
"liquidity",
1158+
"deposit_compensation"
1159+
]
1160+
}
1161+
}
1162+
}
11511163
</code></pre><p><strong>address_balance_ranking</strong>:<br></p><pre><code>{
11521164
"data": {
11531165
"id": "1562726172",
@@ -1208,6 +1220,18 @@
12081220
}
12091221
}
12101222
}
1223+
</code></pre><p><strong>maintenance_info</strong>:<br></p><pre><code>{
1224+
"data": {
1225+
"id": "1594105429",
1226+
"type": "statistic",
1227+
"attributes": {
1228+
"maintenance_info": {
1229+
"start_at": "1591632000",
1230+
"end_at": "1591639200"
1231+
}
1232+
}
1233+
}
1234+
}
12111235
</code></pre></div><h2>HTTP status code <a href="http://httpstatus.es/404" target="_blank">404</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>message</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>errors</strong>: <em><span class="required">required</span>(array of error)</em><p><strong>Items</strong>: error</p><div class="items"><ul><li><strong>id</strong>: <em><span class="required">required</span>(string)</em><p>A unique identifier for the specific instance of the error</p></li><li><strong>code</strong>: <em><span class="required">required</span>(string)</em><p>an application-specific error code</p></li><li><strong>status</strong>: <em><span class="required">required</span>(string)</em><p>the HTTP status code applicable to this problem</p></li><li><strong>title</strong>: <em><span class="required">required</span>(string)</em><p>a short, human-readable summary of the problem</p></li><li><strong>detail</strong>: <em><span class="required">required</span>(string)</em><p>A more in-depth, human-readable description of the error and how to resolve it</p></li><li><strong>href</strong>: <em><span class="required">required</span>(string)</em><p>A URL that the developer can use to learn more about the issue</p></li></ul></div></li></ul><p><strong>Example</strong>:</p><div class="examples"><pre><code>{
12121236
"message": "Record Not Found",
12131237
"errors": [

test/controllers/api/v1/daily_statistics_controller_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class DailyStatisticsControllerTest < ActionDispatch::IntegrationTest
4848
end
4949

5050
test "should return addresses count and timestamp" do
51-
daily_statistic_data = create_list(:daily_statistic, 15)
51+
create_list(:daily_statistic, 15)
52+
daily_statistic_data = DailyStatistic.order(:created_at_unixtimestamp)
5253
valid_get api_v1_daily_statistic_url("addresses_count")
5354

5455
assert_equal [%w(addresses_count created_at_unixtimestamp).sort], json.dig("data").map { |item| item.dig("attributes").keys.sort }.uniq

0 commit comments

Comments
 (0)