Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 14:01:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-19 14:01:45 +0300
commit9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch)
tree865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/finders/members_finder_spec.rb
parent6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff)
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/finders/members_finder_spec.rb')
-rw-r--r--spec/finders/members_finder_spec.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/finders/members_finder_spec.rb b/spec/finders/members_finder_spec.rb
index 4df6197e3b0..e0fc494d033 100644
--- a/spec/finders/members_finder_spec.rb
+++ b/spec/finders/members_finder_spec.rb
@@ -161,6 +161,27 @@ RSpec.describe MembersFinder, feature_category: :groups_and_projects do
expect(result).to eq([member3, member2, member1])
end
+ it 'avoids N+1 database queries on accessing user records' do
+ project.add_maintainer(user2)
+
+ # warm up
+ # We need this warm up because there is 1 query being fired in one of the policies,
+ # and policy results are cached. Without a warm up, the control_count will be X queries
+ # but the test phase will only fire X-1 queries, due the fact that the
+ # result of the policy is already available in the cache.
+ described_class.new(project, user2).execute.map(&:user)
+
+ control_count = ActiveRecord::QueryRecorder.new do
+ described_class.new(project, user2).execute.map(&:user)
+ end
+
+ create_list(:project_member, 3, project: project)
+
+ expect do
+ described_class.new(project, user2).execute.map(&:user)
+ end.to issue_same_number_of_queries_as(control_count)
+ end
+
context 'with :shared_into_ancestors' do
let_it_be(:invited_group) do
create(:group).tap do |invited_group|