summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2016-07-07 16:08:06 -0400
committerAlejandro Rodríguez <alejorro70@gmail.com>2016-07-20 15:14:31 -0400
commitea63346df5a420cebbc44491eef8e2d2a0fb5ad7 (patch)
tree9776cf9ed91242a830da2294037525d73c6d58d8 /app/models/user.rb
parentb4717017e7ad601eaa1d53c9238a242c7fdf0daa (diff)
downloadgitlab-ce-ea63346df5a420cebbc44491eef8e2d2a0fb5ad7.tar.gz
Refactor user authorization check for a single project to avoid querying all user projects
Currently, even when searching for all authorized issues of *one* project, we run the `Users#authorized_projects` query (which can be rather slow). This update checks if we are handling issues of just one project and does the authorization check locally. It does have the downside of basically repeating the logic of `Users#authorized_projects` on `Project#authorized_for_user`.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 975e935fa20..8dc10becd69 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -412,6 +412,8 @@ class User < ActiveRecord::Base
end
# Returns projects user is authorized to access.
+ #
+ # If you change the logic of this method, please also update `Project#authorized_for_user`
def authorized_projects(min_access_level = nil)
Project.where("projects.id IN (#{projects_union(min_access_level).to_sql})")
end