Commit 2b6b8643 authored by Stan Hu's avatar Stan Hu

Cache the last usage data to avoid unicorn timeouts

Closes #1044
parent 2b252c9a
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
## 8.13.0 (2016-10-22) ## 8.13.0 (2016-10-22)
v 8.13.0 (unreleased)
- Cache the last usage data to avoid unicorn timeouts
- Add user activity table and service to query for active users - Add user activity table and service to query for active users
- Fix 500 error updating mirror URLs for projects - Fix 500 error updating mirror URLs for projects
......
...@@ -15,7 +15,7 @@ class GitlabUsagePingWorker ...@@ -15,7 +15,7 @@ class GitlabUsagePingWorker
begin begin
HTTParty.post(url, HTTParty.post(url,
body: Gitlab::UsageData.to_json, body: Gitlab::UsageData.to_json(true),
headers: { 'Content-type' => 'application/json' } headers: { 'Content-type' => 'application/json' }
) )
rescue HTTParty::Error => e rescue HTTParty::Error => e
......
module Gitlab module Gitlab
class UsageData class UsageData
class << self class << self
def data def data(force_refresh = false)
Rails.cache.fetch('usage_data', expires_in: 1.hour) { uncached_data } Rails.cache.fetch('usage_data', force: force_refresh) { uncached_data }
end end
def uncached_data def uncached_data
license_usage_data.merge(system_usage_data) license_usage_data.merge(system_usage_data)
end end
def to_json def to_json(force_refresh = false)
data.to_json data(force_refresh).to_json
end end
def system_usage_data def system_usage_data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment