Skip to content

Commit

Permalink
Remove method discard_cache?
Browse files Browse the repository at this point in the history
This method never really worked and the idea behind was to
allow the client to invalidate the server cache remotely
  • Loading branch information
vpereira committed Sep 13, 2018
1 parent 52f4f55 commit 63c6b25
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/api/app/controllers/webui/monitor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def events
range = params[:range]

['waiting', 'blocked', 'squeue_high', 'squeue_med'].each do |prefix|
data[prefix] = gethistory("#{prefix}_#{arch.name}", range, !discard_cache?).map { |time, value| [time * 1000, value] }
data[prefix] = gethistory("#{prefix}_#{arch.name}", range).map { |time, value| [time * 1000, value] }
end

['idle', 'building', 'away', 'down', 'dead'].each do |prefix|
data[prefix] = gethistory("#{prefix}_#{arch.worker}", range, !discard_cache?).map { |time, value| [time * 1000, value] }
data[prefix] = gethistory("#{prefix}_#{arch.worker}", range).map { |time, value| [time * 1000, value] }
end

low = Hash[gethistory("squeue_low_#{arch}", range)]
Expand All @@ -107,24 +107,10 @@ def events
render json: data
end

protected

def discard_cache?
cc = request.headers['HTTP_CACHE_CONTROL']
return false if cc.blank?
return true if cc == 'max-age=0'
return false unless cc == 'no-cache'
!request.xhr?
end

private

def gethistory(key, range, cache = 1)
def gethistory(key, range)
cachekey = "#{key}-#{range}"
Rails.cache.delete(cachekey, shared: true) unless cache
Rails.cache.fetch(cachekey, expires_in: (range.to_i * 3600) / 150, shared: true) do
hash = StatusHistory.history_by_key_and_hours(key, range)
hash.sort_by { |a| a[0] }
StatusHistory.history_by_key_and_hours(key, range).sort_by { |a| a[0] }
end
end

Expand Down

0 comments on commit 63c6b25

Please sign in to comment.