Commit c283fba3b7e9fb89ae2ed77597adee2700982718
1 parent
5921c748
Exists in
spb-stable
and in
2 other branches
Improve performance of application for large teams
This commit fixes a lot of sql queries to db for for groups and projects with big amount of members. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
49 additions
and
11 deletions
Show diff stats
CHANGELOG
| @@ -17,6 +17,7 @@ v 7.0.0 | @@ -17,6 +17,7 @@ v 7.0.0 | ||
| 17 | - UI improvements | 17 | - UI improvements |
| 18 | - Case-insensetive search for issues | 18 | - Case-insensetive search for issues |
| 19 | - Update to rails 4.1 | 19 | - Update to rails 4.1 |
| 20 | + - Improve performance of application for projects and groups with a lot of members | ||
| 20 | 21 | ||
| 21 | v 6.9.2 | 22 | v 6.9.2 |
| 22 | - Revert the commit that broke the LDAP user filter | 23 | - Revert the commit that broke the LDAP user filter |
app/models/ability.rb
| @@ -71,16 +71,16 @@ class Ability | @@ -71,16 +71,16 @@ class Ability | ||
| 71 | team = project.team | 71 | team = project.team |
| 72 | 72 | ||
| 73 | # Rules based on role in project | 73 | # Rules based on role in project |
| 74 | - if team.masters.include?(user) | 74 | + if team.master?(user) |
| 75 | rules += project_master_rules | 75 | rules += project_master_rules |
| 76 | 76 | ||
| 77 | - elsif team.developers.include?(user) | 77 | + elsif team.developer?(user) |
| 78 | rules += project_dev_rules | 78 | rules += project_dev_rules |
| 79 | 79 | ||
| 80 | - elsif team.reporters.include?(user) | 80 | + elsif team.reporter?(user) |
| 81 | rules += project_report_rules | 81 | rules += project_report_rules |
| 82 | 82 | ||
| 83 | - elsif team.guests.include?(user) | 83 | + elsif team.guest?(user) |
| 84 | rules += project_guest_rules | 84 | rules += project_guest_rules |
| 85 | end | 85 | end |
| 86 | 86 |
app/models/project_team.rb
| @@ -117,6 +117,22 @@ class ProjectTeam | @@ -117,6 +117,22 @@ class ProjectTeam | ||
| 117 | false | 117 | false |
| 118 | end | 118 | end |
| 119 | 119 | ||
| 120 | + def guest?(user) | ||
| 121 | + find_tm(user.id).access_field == Gitlab::Access::GUEST | ||
| 122 | + end | ||
| 123 | + | ||
| 124 | + def reporter?(user) | ||
| 125 | + find_tm(user.id).access_field == Gitlab::Access::REPORTER | ||
| 126 | + end | ||
| 127 | + | ||
| 128 | + def developer?(user) | ||
| 129 | + find_tm(user.id).access_field == Gitlab::Access::DEVELOPER | ||
| 130 | + end | ||
| 131 | + | ||
| 132 | + def master?(user) | ||
| 133 | + find_tm(user.id).access_field == Gitlab::Access::MASTER | ||
| 134 | + end | ||
| 135 | + | ||
| 120 | private | 136 | private |
| 121 | 137 | ||
| 122 | def fetch_members(level = nil) | 138 | def fetch_members(level = nil) |
spec/models/project_team_spec.rb
| 1 | require "spec_helper" | 1 | require "spec_helper" |
| 2 | 2 | ||
| 3 | describe ProjectTeam do | 3 | describe ProjectTeam do |
| 4 | - let(:team) { create(:project).team } | 4 | + let(:group) { create(:group) } |
| 5 | + let(:project) { create(:empty_project, group: group) } | ||
| 5 | 6 | ||
| 6 | - describe "Respond to" do | ||
| 7 | - subject { team } | 7 | + let(:master) { create(:user) } |
| 8 | + let(:reporter) { create(:user) } | ||
| 9 | + let(:guest) { create(:user) } | ||
| 10 | + let(:nonmember) { create(:user) } | ||
| 8 | 11 | ||
| 9 | - it { should respond_to(:developers) } | ||
| 10 | - it { should respond_to(:masters) } | ||
| 11 | - it { should respond_to(:reporters) } | ||
| 12 | - it { should respond_to(:guests) } | 12 | + before do |
| 13 | + group.add_user(master, Gitlab::Access::MASTER) | ||
| 14 | + group.add_user(reporter, Gitlab::Access::REPORTER) | ||
| 15 | + group.add_user(guest, Gitlab::Access::GUEST) | ||
| 16 | + | ||
| 17 | + # Add group guest as master to this project | ||
| 18 | + # to test project access priority over group members | ||
| 19 | + project.team << [guest, :master] | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + describe 'members collection' do | ||
| 23 | + it { team.masters.should include(master) } | ||
| 24 | + it { team.masters.should include(guest) } | ||
| 25 | + it { team.masters.should_not include(reporter) } | ||
| 26 | + it { team.masters.should_not include(nonmember) } | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + describe 'access methods' do | ||
| 30 | + it { team.master?(master).should be_true } | ||
| 31 | + it { team.master?(guest).should be_true } | ||
| 32 | + it { team.master?(reporter).should be_false } | ||
| 33 | + it { team.master?(nonmember).should be_false } | ||
| 13 | end | 34 | end |
| 14 | end | 35 | end |
| 15 | 36 |