diff --git a/CHANGELOG.md b/CHANGELOG.md index 12315b1f7..3a6c1ca7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +# [v0.9.9](https://github.com/nervosnetwork/ckb-explorer/compare/v0.9.8...v0.9.9) (2020-07-09) + + +### Bug Fixes + +* [#669](https://github.com/nervosnetwork/ckb-explorer/pull/669): fix ActiveRecord::IrreversibleOrderError + + +### Features + +* [#677](https://github.com/nervosnetwork/ckb-explorer/pull/677): update dao compensation logic to include the unclaimed compensation +* [#680](https://github.com/nervosnetwork/ckb-explorer/pull/680): add maintenance info API +* [#682](https://github.com/nervosnetwork/ckb-explorer/pull/682): add flush front-end cache API + +### Performance Improvements + +* [#699](https://github.com/nervosnetwork/ckb-explorer/pull/669): use separate query and just select needed field +* [#670](https://github.com/nervosnetwork/ckb-explorer/pull/670): use recent scope on block query +* [#675](https://github.com/nervosnetwork/ckb-explorer/pull/675): add cache on blockchain info + # [v0.9.8](https://github.com/nervosnetwork/ckb-explorer/compare/v0.9.7...v0.9.8) (2020-06-29) diff --git a/app/controllers/api/v1/daily_statistics_controller.rb b/app/controllers/api/v1/daily_statistics_controller.rb index 6eeec467a..9ba9ecdbf 100644 --- a/app/controllers/api/v1/daily_statistics_controller.rb +++ b/app/controllers/api/v1/daily_statistics_controller.rb @@ -4,7 +4,7 @@ class DailyStatisticsController < ApplicationController before_action :validate_query_params, only: :show def show - daily_statistics = DailyStatistic.order(:created_at_unixtimestamp).limit(365) + daily_statistics = DailyStatistic.order(:created_at_unixtimestamp) render json: DailyStatisticSerializer.new(daily_statistics, { params: { indicator: params[:id] } }) end diff --git a/app/models/statistic_info.rb b/app/models/statistic_info.rb index f7bef85d9..569122e8e 100644 --- a/app/models/statistic_info.rb +++ b/app/models/statistic_info.rb @@ -81,6 +81,14 @@ def blockchain_info end end + def maintenance_info + Rails.cache.fetch("maintenance_info") + end + + def flush_cache_info + Rails.cache.realize("flush_cache_info") || [] + end + private attr_reader :hash_rate_statistical_interval, :average_block_time_interval diff --git a/app/serializers/statistic_serializer.rb b/app/serializers/statistic_serializer.rb index 6aabc795f..bd02b4c27 100644 --- a/app/serializers/statistic_serializer.rb +++ b/app/serializers/statistic_serializer.rb @@ -25,7 +25,15 @@ class StatisticSerializer params && params[:info_name] == "blockchain_info" } + attribute :flush_cache_info, if: Proc.new { |_record, params| + params && params[:info_name] == "flush_cache_info" + } + attribute :address_balance_ranking, if: Proc.new { |_record, params| params && params[:info_name] == "address_balance_ranking" } + + attribute :maintenance_info, if: Proc.new { |_record, params| + params && params[:info_name] == "maintenance_info" + } end diff --git a/doc/api.raml b/doc/api.raml index 2a6130096..cdc2df292 100644 --- a/doc/api.raml +++ b/doc/api.raml @@ -540,12 +540,30 @@ types: "hash_rate": { type: "string", }, + "flush_cache_info": { + type: "string[]" + } "blockchain_info": { type: "object" }, "address_balance_ranking": { type: "address_balance_ranking" } + "maintenance_info": { + type: "maintenance_info" + } + } + } + + maintenance_info: { + type: object, + properties: { + "stat_at": { + type: "string" + }, + "end_at": { + type: "string" + } } } @@ -2414,6 +2432,19 @@ types: } } } + flush_cache_info: | + { + "data": { + "id": "1594109792", + "type": "statistic", + "attributes": { + "flush_cache_info": [ + "liquidity", + "deposit_compensation" + ] + } + } + } address_balance_ranking: | { "data": { @@ -2475,6 +2506,19 @@ types: } } } + maintenance_info: | + { + "data": { + "id": "1594105429", + "type": "statistic", + "attributes": { + "maintenance_info": { + "start_at": "1591632000", + "end_at": "1591639200" + } + } + } + } 404: body: application/vnd.api+json: diff --git a/lib/tasks/set_flush_cache_info.rake b/lib/tasks/set_flush_cache_info.rake new file mode 100644 index 000000000..6c9965e37 --- /dev/null +++ b/lib/tasks/set_flush_cache_info.rake @@ -0,0 +1,14 @@ +desc "Usage: RAILS_ENV=production bundle exec rake 'set_flush_cache_info[liquidity deposit_compensation, true]'" +task :set_flush_cache_info, [:indicators, :dry_run] => :environment do |_, args| + raise "please input indicators" if args[:indicators].blank? + binding.pry + + indicators = args[:indicators].split(" ") + dry_run = args[:dry_run] || "true" + if dry_run == "true" + puts "indicators: #{indicators.join(", ")}" + else + Rails.cache.write("flush_cache_info", indicators, expires_in: 1.day) + puts "done" + end +end diff --git a/lib/tasks/set_maintenance_info.rake b/lib/tasks/set_maintenance_info.rake new file mode 100644 index 000000000..d56ac5da4 --- /dev/null +++ b/lib/tasks/set_maintenance_info.rake @@ -0,0 +1,20 @@ +desc "Usage: RAILS_ENV=production bundle exec rake 'set_maintenance_info[2020-06-09 00:00:00, nil]'" +task :set_maintenance_info, [:start_at, :end_at, :dry_run] => :environment do |_, args| + raise "please input start at" if args[:start_at].blank? + + start_at = Time.parse(args[:start_at]).utc + dry_run = args[:dry_run] || "true" + if args[:end_at] != "nil" + end_at = Time.parse(args[:end_at]).utc + else + end_at = start_at + 2.hours + end + if dry_run == "true" + puts "start_at: #{start_at}" + puts "end_at: #{end_at}" + else + info = { start_at: start_at.to_i.to_s, end_at: end_at.to_i.to_s } + puts "inf: #{info}" + Rails.cache.write("maintenance_info", info) + end +end diff --git a/public/api_doc.html b/public/api_doc.html index 62071c180..c8a5b2ca4 100644 --- a/public/api_doc.html +++ b/public/api_doc.html @@ -1083,7 +1083,7 @@ } ] } -

get

get

Returns the specific statistic info

get

get

Returns the specific statistic info