Skip to content

Commit

Permalink
cache updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 25, 2024
1 parent 7298e29 commit 04729a7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/stocks/chart_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def show

time_range = params[:time_range].presence || "1M" # Set default if nil or empty

@stock_chart = Rails.cache.fetch("stock_chart/v1/#{@stock.symbol}:#{@stock.mic_code}/#{time_range}", expires_in: 12.hours) do
@stock_chart = Rails.cache.fetch("stock_chart/v2/#{@stock.symbol}:#{@stock.mic_code}/#{time_range}", expires_in: 12.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stocks/info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
@stock = Stock.find_by(symbol: params[:stock_ticker], country_code: "US")
end

@stock_info = Rails.cache.fetch("stock_info/v1/#{@stock.symbol}:#{@stock.mic_code}", expires_in: 24.hours) do
@stock_info = Rails.cache.fetch("stock_info/v2/#{@stock.symbol}:#{@stock.mic_code}", expires_in: 24.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stocks/price_performance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def show
end
timeframe = params[:timeframe] || "24h"

@price_performance = Rails.cache.fetch("price_performance/v1/#{@stock.symbol}:#{@stock.mic_code}/#{timeframe}", expires_in: 12.hours) do
@price_performance = Rails.cache.fetch("price_performance/v2/#{@stock.symbol}:#{@stock.mic_code}/#{timeframe}", expires_in: 12.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stocks/similar_stocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
@stock = Stock.find_by(symbol: params[:stock_ticker], country_code: "US")
end

@similar_stocks_data = Rails.cache.fetch("similar_stocks/v1/#{@stock.symbol}/#{@stock.mic_code}", expires_in: 6.hours) do
@similar_stocks_data = Rails.cache.fetch("similar_stocks/v2/#{@stock.symbol}/#{@stock.mic_code}", expires_in: 6.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stocks/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
@stock = Stock.find_by(symbol: params[:stock_ticker], country_code: "US")
end

@stock_statistics = Rails.cache.fetch("stock_statistics/v1/#{@stock.symbol}:#{@stock.mic_code}", expires_in: 24.hours) do
@stock_statistics = Rails.cache.fetch("stock_statistics/v2/#{@stock.symbol}:#{@stock.mic_code}", expires_in: 24.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/stocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StocksController < ApplicationController
# GET /stocks
# GET /stocks?q=AAPL
def index
@exchanges = Rails.cache.fetch("stock_exchanges_groupings/v1", expires_in: 24.hours) do
@exchanges = Rails.cache.fetch("stock_exchanges_groupings/v2", expires_in: 24.hours) do
Stock.where(kind: "stock")
.where.not(mic_code: nil)
.distinct
Expand All @@ -24,11 +24,11 @@ def index
.sort_by(&:first)
end

@industries = Rails.cache.fetch("stock_industries_groupings/v1", expires_in: 24.hours) do
@industries = Rails.cache.fetch("stock_industries_groupings/v2", expires_in: 24.hours) do
Stock.where(kind: "stock").where.not(mic_code: nil).where.not(industry: nil).distinct.pluck(:industry, :country_code).compact.sort_by(&:first)
end

@sectors = Rails.cache.fetch("stock_sectors_groupings/v1", expires_in: 24.hours) do
@sectors = Rails.cache.fetch("stock_sectors_groupings/v2", expires_in: 24.hours) do
Stock.where(kind: "stock").where.not(mic_code: nil).where.not(sector: nil).distinct.pluck(:sector).compact.sort
end

Expand Down Expand Up @@ -91,7 +91,7 @@ def exchanges
if params[:id]
@exchange = params[:id]
if @exchange.present?
scope = Rails.cache.fetch("exchange_stocks/#{@exchange}/v1", expires_in: 12.hours) do
scope = Rails.cache.fetch("exchange_stocks/#{@exchange}/v2", expires_in: 12.hours) do
Stock.where(exchange: @exchange).where.not(mic_code: nil).order(:name)
end
return redirect_to stocks_path if scope.empty?
Expand All @@ -102,7 +102,7 @@ def exchanges
redirect_to stocks_path and return
end
else
@exchanges = Rails.cache.fetch("exchanges_list/v1", expires_in: 24.hours) do
@exchanges = Rails.cache.fetch("exchanges_list/v2", expires_in: 24.hours) do
Stock.where(kind: "stock")
.where.not(mic_code: nil)
.distinct
Expand Down

0 comments on commit 04729a7

Please sign in to comment.