diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-02 16:01:06 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-02 18:23:03 +0100 |
commit | 39011be53daee921dac1648044d1e68b9706197c (patch) | |
tree | 695cbcfa7346f2d4f8a4c566bd6f0ae31dd4f5c5 /app/models/project.rb | |
parent | 0a3fc7e3c283c10ef8415a719e83e80f0122af7d (diff) | |
download | gitlab-ce-42877-fix-visibility-change-performance.tar.gz |
Extract method User#authorizations_for_projects.42877-fix-visibility-change-performance
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index ad4315e1601..5b1f8b2658b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -319,14 +319,9 @@ class Project < ActiveRecord::Base # logged in user. def self.public_or_visible_to_user(user = nil) if user - authorized = user - .project_authorizations - .select(1) - .where('project_authorizations.project_id = projects.id') - - levels = Gitlab::VisibilityLevel.levels_for_user(user) - - where('EXISTS (?) OR projects.visibility_level IN (?)', authorized, levels) + where('EXISTS (?) OR projects.visibility_level IN (?)', + user.authorizations_for_projects, + Gitlab::VisibilityLevel.levels_for_user(user)) else public_to_user end @@ -347,14 +342,11 @@ class Project < ActiveRecord::Base elsif user column = ProjectFeature.quoted_access_level_column(feature) - authorized = user.project_authorizations.select(1) - .where('project_authorizations.project_id = projects.id') - with_project_feature .where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))", visible, ProjectFeature::PRIVATE, - authorized) + user.authorizations_for_projects) else with_feature_access_level(feature, visible) end |