diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-04-06 14:30:16 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-04-06 14:30:16 +0300 |
commit | 9dc276dd45702a159b3f14081c7ee6bd80f80f09 (patch) | |
tree | 3314ab702b3ebe5771e045cbde2fd7341e88b656 /app/models | |
parent | 132de986ee985f0651e874a45847f9ed2ea31af7 (diff) | |
parent | fa46b19ddb82851523fabaea2fca4660c181db89 (diff) |
Merge branch 'ab-37462-cache-personal-projects-count' into 'master'
Cache personal projects count.
Closes #37462
See merge request gitlab-org/gitlab-ce!18197
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index ce56b39b1c8..2b95be3f888 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,12 @@ 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_todos_count_cache todos_done_count(force: true) todos_pending_count(force: true) @@ -1056,6 +1058,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 +1077,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). # |