Investigate N+1 queries permitted by with_threshold in tests
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=413620)
</details>
<!--IssueSummary end-->
### Problem to solve
We have tests that have underlying N+1s that are still permitted by using `with_threshold` method. This method sets a number of queries that can be performed above the limit. After https://gitlab.com/gitlab-org/gitlab/-/merge_requests/90907 some of those threshold has been increased. Let's use this issue to investigate whether some of these thresholds can be decreased or removed.
```ruby
spec/graphql/resolvers/users/participants_resolver_spec.rb
140: expect { query.call }.not_to exceed_query_limit(control_count).with_threshold(7)
spec/requests/api/graphql/current_user/todos_query_spec.rb
81: expect { post_graphql(query, current_user: current_user) }.not_to exceed_query_limit(control).with_threshold(2)
spec/requests/api/todos_spec.rb
262: expect { get api('/todos', john_doe) }.not_to exceed_query_limit(control1).with_threshold(5)
270: expect { get api('/todos', john_doe) }.not_to exceed_query_limit(control2).with_threshold(1)
spec/requests/api/branches_spec.rb
282: end.not_to exceed_query_limit(control).with_threshold(1)
spec/requests/projects/merge_requests_discussions_spec.rb
41: end.not_to exceed_query_limit(control).with_threshold(notes_metadata_threshold)
spec/services/notification_recipients/build_service_spec.rb
30: expect { service.build_new_note_recipients(note) }.not_to exceed_query_limit(control_count).with_threshold(threshold)
85: expect { service.build_new_review_recipients(review) }.not_to exceed_query_limit(control_count).with_threshold(threshold)
spec/controllers/groups/children_controller_spec.rb
218: expect { get_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_group)
225: expect { get_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_project + 1)
244: expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(extra_queries_for_hierarchies)
255: expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(extra_queries_for_hierarchies)
265: expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(extra_queries_for_hierarchies)
spec/controllers/explore/projects_controller_spec.rb
234: expect { get endpoint }.not_to exceed_query_limit(control).with_threshold(8)
spec/controllers/projects/issues_controller_spec.rb
1812: .not_to exceed_query_limit(control).with_threshold(9)
spec/lib/gitlab/git_access_spec.rb
1072: expect { access.check('git-receive-pack', changes) }.not_to exceed_query_limit(control_count).with_threshold(2)
spec/support/shared_examples/graphql/n_plus_one_query_examples.rb
18: exceed_query_limit(control).with_threshold(threshold)
spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb
42: expect { get(url, headers: headers) }.not_to exceed_query_limit(control).with_threshold(4)
spec/models/project_spec.rb
6558: .not_to exceed_query_limit(control).with_threshold(2)
spec/features/dashboard/projects_spec.rb
263: expect { visit dashboard_projects_path }.not_to exceed_query_limit(control).with_threshold(4)
spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
69: expect { perform(Upload.all) }.not_to exceed_query_limit(query_count).with_threshold(5)
ee/spec/services/epics/epic_links/create_service_spec.rb
434: end.not_to exceed_query_limit(control).with_threshold(8)
ee/spec/helpers/projects/project_members_helper_spec.rb
37: expect { call_project_members_app_data_json }.not_to exceed_query_limit(control_count).with_threshold(11) # existing n+1
ee/spec/controllers/projects/feature_flag_issues_controller_spec.rb
147: expect { get_request(project, feature_flag) }.not_to exceed_query_limit(control_count).with_threshold(4)
ee/spec/graphql/types/pipeline_security_report_finding_type_spec.rb
341: end.not_to exceed_query_limit(initial_query).with_threshold(1)
ee/spec/serializers/merge_request_widget_entity_spec.rb
51: expect { serializer.represent(merge_request) }.not_to exceed_query_limit(control).with_threshold(1)
ee/spec/models/preloaders/environments/protected_environment_preloader_spec.rb
35: expect { staging.protected? }.not_to exceed_query_limit(0).with_threshold(1) # 1 project load is expected
ee/spec/models/epic_spec.rb
1095: .not_to exceed_query_limit(control).with_threshold(4)
ee/spec/requests/api/search_spec.rb
149: expect { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } }.not_to exceed_query_limit(control).with_threshold(5)
290: expect { get api(endpoint, user), params: { scope: 'projects', search: '*' } }.not_to exceed_query_limit(control).with_threshold(4)
ee/spec/requests/api/todos_spec.rb
51: expect { get api('/todos', personal_access_token: pat) }.not_to exceed_query_limit(control).with_threshold(1)
ee/spec/requests/api/vulnerability_findings_spec.rb
101: expect { get api(project_vulnerability_findings_path, user) }.not_to exceed_query_limit(control_count).with_threshold(1)
ee/spec/requests/api/graphql/project/branch_rules/approval_project_rules_spec.rb
94: end.not_to exceed_query_limit(control).with_threshold(number_of_rules * 2) # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/376723
ee/spec/requests/api/graphql/project/incident_management/oncall_shifts_spec.rb
118: expect { post_graphql(query, current_user: current_user) }.not_to exceed_query_limit(base_count).with_threshold(2)
ee/spec/requests/api/graphql/project/environments_spec.rb
245: expect(multi).not_to exceed_query_limit(baseline).with_threshold(1)
ee/spec/requests/api/graphql/group/epic/epic_issues_spec.rb
145: end.not_to exceed_query_limit(control_count).with_threshold(extra_queries_count)
ee/spec/requests/api/graphql/group/epic/epic_children_spec.rb
153: end.not_to exceed_query_limit(control_count).with_threshold(extra_queries)
ee/spec/requests/projects/merge_requests_controller_spec.rb
32: expect { get_edit }.not_to exceed_query_limit(control).with_threshold(3)
```
issue