diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-04 17:43:01 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-07 13:38:32 +0300 |
commit | ab738645a7b5bba46c8bf50f0780e66befc8bbe2 (patch) | |
tree | a053f0114731ec4c759171cd83dcb6468fefa03a /app | |
parent | 4a915c739d502a8b1d2a019f4352d46a3be3d7e0 (diff) |
Memoize a user's personal projects count
The method User#projects_limit_left would run "personal_projects.count"
but such a query is not memoized. As a result multiple calls to
User#projects_limit_left would result in multiple COUNT(*) queries being
executed.
To work around this this commit adds User#personal_projects_count which
simply memoizes the result of the COUNT(*) in an instance variable.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index afcadfe484e..5148886eed7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -632,7 +632,11 @@ class User < ActiveRecord::Base end def projects_limit_left - projects_limit - personal_projects.count + projects_limit - personal_projects_count + end + + def personal_projects_count + @personal_projects_count ||= personal_projects.count end def projects_limit_percent |