FIX: more resilient/consistent dashboard caching (#6223)

This commit is contained in:
Joffrey JAFFEUX 2018-08-01 09:45:50 -04:00 committed by GitHub
parent c8c2bdda79
commit 0b9437cee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 12 deletions

View File

@ -5,8 +5,8 @@ module Jobs
sidekiq_options retry: false
def execute(args)
$redis.set(DiskSpace::DISK_SPACE_STATS_CACHE_KEY, DiskSpace.stats.to_json)
$redis.set(DiskSpace::DISK_SPACE_STATS_UPDATED_CACHE_KEY, Time.now.to_i)
Discourse.cache.write(DiskSpace::DISK_SPACE_STATS_CACHE_KEY, DiskSpace.stats.to_json)
Discourse.cache.write(DiskSpace::DISK_SPACE_STATS_UPDATED_CACHE_KEY, Time.now.to_i)
end
end
end

View File

@ -14,7 +14,7 @@ class AdminDashboardNextGeneralData < AdminDashboardNextData
def get_json
{
reports: self.class.reports(reports),
reports: self.class.reports(reports).compact,
updated_at: Time.zone.now.as_json
}
end

View File

@ -147,12 +147,10 @@ class Report
end
def self.cache(report, duration)
Discourse.cache.write(Report.cache_key(report), report.as_json, force: true, expires_in: duration)
Discourse.cache.write(cache_key(report), report.as_json, force: true, expires_in: duration)
end
def self.find(type, opts = nil)
clear_cache
begin
report = _get(type, opts)
report_method = :"report_#{type}"

View File

@ -41,14 +41,13 @@ class DiskSpace
end
def self.reset_cached_stats
$redis.del(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
$redis.del(DISK_SPACE_STATS_CACHE_KEY)
Jobs.enqueue(:update_disk_space)
Discourse.cache.delete(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
Discourse.cache.delete(DISK_SPACE_STATS_CACHE_KEY)
end
def self.cached_stats
stats = $redis.get(DISK_SPACE_STATS_CACHE_KEY)
updated_at = $redis.get(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
stats = Discourse.cache.read(DISK_SPACE_STATS_CACHE_KEY)
updated_at = Discourse.cache.read(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
unless updated_at && (Time.now.to_i - updated_at.to_i) < 30.minutes
Jobs.enqueue(:update_disk_space)
@ -68,5 +67,4 @@ class DiskSpace
def self.used(path)
`du -s #{path}`.to_i * 1024
end
end