Skip to content

Commit

Permalink
Merge pull request #5849 from vpereira/http_cache_control
Browse files Browse the repository at this point in the history
Remove the method discard_cache? as it never worked as intended.
  • Loading branch information
vpereira committed Sep 13, 2018
2 parents b02bc9b + 63c6b25 commit ef27aaa
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 ef27aaa

Please sign in to comment.