FIX: more resilient/consistent dashboard caching (#6223)
This commit is contained in:
parent
c8c2bdda79
commit
0b9437cee7
|
@ -5,8 +5,8 @@ module Jobs
|
||||||
sidekiq_options retry: false
|
sidekiq_options retry: false
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
$redis.set(DiskSpace::DISK_SPACE_STATS_CACHE_KEY, DiskSpace.stats.to_json)
|
Discourse.cache.write(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_UPDATED_CACHE_KEY, Time.now.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ class AdminDashboardNextGeneralData < AdminDashboardNextData
|
||||||
|
|
||||||
def get_json
|
def get_json
|
||||||
{
|
{
|
||||||
reports: self.class.reports(reports),
|
reports: self.class.reports(reports).compact,
|
||||||
updated_at: Time.zone.now.as_json
|
updated_at: Time.zone.now.as_json
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -147,12 +147,10 @@ class Report
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cache(report, duration)
|
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
|
end
|
||||||
|
|
||||||
def self.find(type, opts = nil)
|
def self.find(type, opts = nil)
|
||||||
clear_cache
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
report = _get(type, opts)
|
report = _get(type, opts)
|
||||||
report_method = :"report_#{type}"
|
report_method = :"report_#{type}"
|
||||||
|
|
|
@ -41,14 +41,13 @@ class DiskSpace
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.reset_cached_stats
|
def self.reset_cached_stats
|
||||||
$redis.del(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
|
Discourse.cache.delete(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
|
||||||
$redis.del(DISK_SPACE_STATS_CACHE_KEY)
|
Discourse.cache.delete(DISK_SPACE_STATS_CACHE_KEY)
|
||||||
Jobs.enqueue(:update_disk_space)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cached_stats
|
def self.cached_stats
|
||||||
stats = $redis.get(DISK_SPACE_STATS_CACHE_KEY)
|
stats = Discourse.cache.read(DISK_SPACE_STATS_CACHE_KEY)
|
||||||
updated_at = $redis.get(DISK_SPACE_STATS_UPDATED_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
|
unless updated_at && (Time.now.to_i - updated_at.to_i) < 30.minutes
|
||||||
Jobs.enqueue(:update_disk_space)
|
Jobs.enqueue(:update_disk_space)
|
||||||
|
@ -68,5 +67,4 @@ class DiskSpace
|
||||||
def self.used(path)
|
def self.used(path)
|
||||||
`du -s #{path}`.to_i * 1024
|
`du -s #{path}`.to_i * 1024
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue