Commit 0c77dec3 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'license-check-performance' into 'master'

Reduce load on DB for license upgrade check

1. Only check if the user is an admin
2. Cache the active user count for an hour

Helps gitlab-com/operations#298

See merge request !421
parents e7e4cf00 b4580b6f
Please view this file on the master branch, on stable branches it's out of date.
v 8.8.3
- Reduce load on DB for license upgrade check
v 8.8.2
- Fix repository mirror updates for new imports stuck in started
- [Elastic] Search through the filenames. !409
......
......@@ -37,7 +37,7 @@ module LicenseHelper
return unless signed_in
return unless ((license.notify_admins? || license.warn_upgrade_license_message?) && is_admin) || license.notify_users?
return unless (is_admin && (license.notify_admins? || license.warn_upgrade_license_message?)) || license.notify_users?
message = []
......
......@@ -92,6 +92,12 @@ class License < ActiveRecord::Base
self.restrictions[:active_user_count]
end
def current_user_count
Rails.cache.fetch("current_active_user_count", expires_in: 1.hour) do
User.active.count
end
end
def warn_upgrade_license_message?
restricted_user_count = user_count
......@@ -99,9 +105,7 @@ class License < ActiveRecord::Base
return false unless Time.now >= self.starts_at + 3.months
active_user_count = User.active.count
restricted_user_count && active_user_count > restricted_user_count
restricted_user_count && current_user_count > restricted_user_count
end
private
......
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