Reduce number of queries in epic_issues services specs
What does this MR do?
Contribution based on data extracted from the rspec profiling project.
Modifies the specs files within ee/spec/services/epic_issues
to reduce DB hits by replacing the helper let
with let_it_be
where possible.
Queries saved: 11479
ee/spec/services/epic_issues/create_service_spec.rb
1. - Number of queries: 13252 -> 6251
- Total Time: 00:31.563 -> 00:16.997
TEST PROF INFO - Before
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/create_service_spec.rb
Running via Spring preloader in process 53066
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.....................................................[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:15.430 of 00:31.563 (48.89%)
Total events: 13252
Top 5 slowest suites (by time):
EpicIssues::CreateService (./ee/spec/services/epic_issues/create_service_spec.rb:5) – 00:15.430 (13252 / 53) of 00:31.563 (48.89%)
Finished in 34.94 seconds (files took 3.65 seconds to load)
53 examples, 0 failures
TEST PROF INFO - After
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/create_service_spec.rb
Running via Spring preloader in process 24095
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.....................................................[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:07.576 of 00:16.997 (44.57%)
Total events: 6251
Top 5 slowest suites (by time):
EpicIssues::CreateService (./ee/spec/services/epic_issues/create_service_spec.rb:5) – 00:07.576 (6251 / 53) of 00:16.997 (44.57%)
Finished in 19.98 seconds (files took 3.26 seconds to load)
53 examples, 0 failures
ee/spec/services/epic_issues/destroy_service_spec.rb
2. - Number of queries: 1725 -> 698
- Total Time: 00:06.064 -> 00:03.757
TEST PROF INFO - Before
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/destroy_service_spec.rb
Running via Spring preloader in process 73127
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.........[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:02.461 of 00:06.064 (40.58%)
Total events: 1725
Top 5 slowest suites (by time):
EpicIssues::DestroyService (./ee/spec/services/epic_issues/destroy_service_spec.rb:5) – 00:02.461 (1725 / 9) of 00:06.064 (40.58%)
Finished in 9.09 seconds (files took 3.19 seconds to load)
9 examples, 0 failures
TEST PROF INFO - After
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/destroy_service_spec.rb
Running via Spring preloader in process 9610
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.........[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.081 of 00:03.757 (28.78%)
Total events: 698
Top 5 slowest suites (by time):
EpicIssues::DestroyService (./ee/spec/services/epic_issues/destroy_service_spec.rb:5) – 00:01.081 (698 / 9) of 00:03.757 (28.78%)
Finished in 6.76 seconds (files took 3.14 seconds to load)
9 examples, 0 failures
ee/spec/services/epic_issues/list_service_spec.rb
3. - Number of queries: 1471 -> 812
- Total Time: 00:06.065 -> 00:04.137
TEST PROF INFO - Before
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/list_service_spec.rb
Running via Spring preloader in process 94729
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
....[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:02.119 of 00:06.065 (34.94%)
Total events: 1471
Top 5 slowest suites (by time):
EpicIssues::ListService (./ee/spec/services/epic_issues/list_service_spec.rb:5) – 00:02.119 (1471 / 4) of 00:06.065 (34.94%)
Finished in 9.01 seconds (files took 3.21 seconds to load)
4 examples, 0 failures
TEST PROF INFO - After
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/list_service_spec.rb
Running via Spring preloader in process 6174
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
....[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.339 of 00:04.137 (32.38%)
Total events: 812
Top 5 slowest suites (by time):
EpicIssues::ListService (./ee/spec/services/epic_issues/list_service_spec.rb:5) – 00:01.339 (812 / 4) of 00:04.137 (32.38%)
Finished in 7.44 seconds (files took 3.28 seconds to load)
4 examples, 0 failures
ee/spec/services/epic_issues/update_service_spec.rb
4. - Number of queries: 3650 -> 858
- Total Time: 00:09.912 -> 00:03.781
TEST PROF INFO - Before
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/update_service_spec.rb
Running via Spring preloader in process 11239
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
........[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:04.958 of 00:09.912 (50.03%)
Total events: 3650
Top 5 slowest suites (by time):
EpicIssues::UpdateService (./ee/spec/services/epic_issues/update_service_spec.rb:5) – 00:04.958 (3650 / 8) of 00:09.912 (50.03%)
Finished in 12.89 seconds (files took 3.14 seconds to load)
8 examples, 0 failures
TEST PROF INFO - After
EVENT_PROF='sql.active_record' bin/rspec ./ee/spec/services/epic_issues/update_service_spec.rb
Running via Spring preloader in process 16088
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
........[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.518 of 00:03.781 (40.15%)
Total events: 858
Top 5 slowest suites (by time):
EpicIssues::UpdateService (./ee/spec/services/epic_issues/update_service_spec.rb:5) – 00:01.518 (858 / 8) of 00:03.781 (40.15%)
Finished in 6.73 seconds (files took 3.11 seconds to load)
8 examples, 0 failures
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Eugenia Grieff