diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-04-04 18:14:19 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-04-06 13:27:20 +0300 |
commit | 29b0a90c208f29606a05d1391a72b9ff7ff843b1 (patch) | |
tree | 0c5e0312ed62271c0221f7f2f887cc694f87c765 /app/models | |
parent | 52b232ca5d18ffc08299f5bb0ef3be46d2fecca3 (diff) |
Cache personal projects count.
Closes #37462.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index ce56b39b1c8..a14aefc61d2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -700,10 +700,6 @@ class User < ActiveRecord::Base projects_limit - personal_projects_count end - def personal_projects_count - @personal_projects_count ||= personal_projects.count - end - def recent_push(project = nil) service = Users::LastPushEventService.new(self) @@ -1046,6 +1042,18 @@ class User < ActiveRecord::Base end end + def personal_projects_count(force: false) + Rails.cache.fetch(['users', id, 'personal_projects_count'], force: force, expires_in: 24.hours, raw: true) do + personal_projects.count + end.to_i + end + + def update_cache_counts + assigned_open_merge_requests_count(force: true) + assigned_open_issues_count(force: true) + personal_projects_count(force: true) + end + def update_todos_count_cache todos_done_count(force: true) todos_pending_count(force: true) @@ -1056,6 +1064,7 @@ class User < ActiveRecord::Base invalidate_merge_request_cache_counts invalidate_todos_done_count invalidate_todos_pending_count + invalidate_personal_projects_count end def invalidate_issue_cache_counts @@ -1074,6 +1083,10 @@ class User < ActiveRecord::Base Rails.cache.delete(['users', id, 'todos_pending_count']) end + def invalidate_personal_projects_count + Rails.cache.delete(['users', id, 'personal_projects_count']) + end + # This is copied from Devise::Models::Lockable#valid_for_authentication?, as our auth # flow means we don't call that automatically (and can't conveniently do so). # |