Skip to content

Commit

Permalink
chore: add cache for market data (#2426)
Browse files Browse the repository at this point in the history
* chore: add cache for market data

* chore: update unmade_dao_interests
  • Loading branch information
rabbitz authored Feb 7, 2025
1 parent f5a2d9d commit 20b9531
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/v1/market_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class MarketDataController < ApplicationController
skip_before_action :check_header_info

def index
expires_in 30.minutes, public: true, stale_while_revalidate: 10.minutes, stale_if_error: 10.minutes
render json: MarketData.new.indicators_json
end

def show
expires_in 30.minutes, public: true, stale_while_revalidate: 10.minutes, stale_if_error: 10.minutes
render json: MarketData.new(indicator: params[:id]).call
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/models/market_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ def total_supply

def unmade_dao_interests
@unmade_dao_interests ||=
begin
tip_dao = tip_block.dao
total = 0
CellOutput.nervos_dao_deposit.
generated_before(tip_block.timestamp).unconsumed_at(tip_block.timestamp).find_each do |cell_output|
total += DaoCompensationCalculator.new(cell_output, tip_dao).call
end
total
Rails.cache.fetch("unmade_dao_interests", expires_in: 1.day) do
# tip_dao = tip_block.dao
# total = 0
# CellOutput.nervos_dao_deposit.generated_before(tip_block.timestamp).unconsumed_at(tip_block.timestamp).find_each do |cell_output|
# total += DaoCompensationCalculator.new(cell_output, tip_dao).call
# end
# total
0
end
end

Expand Down

0 comments on commit 20b9531

Please sign in to comment.