Create search visibility spec users once per file
What does this MR do and why?
Cuts the Elasticsearch search visibility specs in ee/spec/services/ee/search/ from about 167 to 124 minutes of rspec-ee unit time per pipeline in CI (−43 minutes, −26%). Most of their time is setup that each permission table row repeats, not the searches the specs check.
Where the time went
Profile of project_service_milestones_visibility_spec.rb (183 rows) on master, run locally:
| Time | Calls | |
|---|---|---|
| Inside examples | 315s | 183 |
create_user_from_membership |
79s | 549 |
ensure_elasticsearch_index! |
71s | 366 |
Project#update! |
54s | 183 |
Searches (expect_search_results) |
52s | 732 |
| Authorization refreshes | 14s | 324 |
This MR:
- Adds the
with search visibility usersshared context. It creates a user for each membership and target once per file, instead of three users for every row. Each example loads its users by ID, so state memoized on a user doesn't carry over to the next row. The 35 files that usesearch respects visibilityinclude it in place of their threeletdefinitions. - Removes
ensure_elasticsearch_index!from 14 spec files where it ran right beforesearch respects visibility, which indexes again after updating the project and group. Those specbeforeblocks only queue records withtrack!. The wiki specs keep theirs, becauseindex_wiki_blobswrites to the index directly. - Makes the shared example refresh authorizations only for
user_in_shared_group, the user it checks, instead of every group member. With a user for each membership in the group, refreshing all of them cost about as much as creating the users had.
Locally, project_service_milestones_visibility_spec.rb goes from 342s to 251s (−27%), with 0 failures before and after:
| Before | After | |
|---|---|---|
| Inside examples | 315s | 206s |
create_user_from_membership |
79s (549 calls) | 4s (15 calls) |
ensure_elasticsearch_index! |
71s (366 calls) | 48s (183 calls) |
| Authorization refreshes | 14s (324 calls) | 3s (162 calls) |
| Searches | 52s | 53s |
In CI, the 43 minutes saved across the 35 files come to about 55 s off each of the 47 rspec-ee unit pg17 jobs. See the test result summary for each file.
A bigger saving would come from one example per project setting, which would also cut indexing and Project#update! calls (183 rows, but 27 distinct settings, in the milestones table). This MR leaves that for a follow-up.
References
Screenshots or screen recordings
Not applicable: spec-only change.
How to set up and validate locally
Not applicable: spec-only change with no behavior to check manually.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.