Improve performance of 'spec/services/notification_service_spec.rb'
What does this MR do?
Part of #194311 (closed).
Most of the times was spent in the background jobs processing, not the DB, so I think we can still use factories as a middle step, for the sake of not changing too many things at once.
Does this MR meet the acceptance criteria?
Conformity
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Separation of EE specific content
Before
Total for these 4 groups: 97 seconds (without the time to load files).
Keys
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:187
NotificationService
Keys
#new_key
should be truthy
never emails the ghost user
should be empty
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.822 of 00:22.449 (3.66%)
Total events: 406
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.822 (406 / 2) of 00:22.449 (3.66%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:20.534 of 00:22.449 (91.47%)
Total events: 1
Finished in 26.27 seconds (files took 2.31 seconds to load)
2 examples, 0 failures
GpgKeys
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:202
NotificationService
GpgKeys
#new_gpg_key
should be truthy
sends email to key owner
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.772 of 00:22.097 (3.5%)
Total events: 418
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.772 (418 / 2) of 00:22.097 (3.5%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:19.538 of 00:22.097 (88.42%)
Total events: 2
Finished in 26.01 seconds (files took 2.1 seconds to load)
2 examples, 0 failures
AccessToken
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:214
NotificationService
AccessToken
#access_token_about_to_expire
sends email to the token owner
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.676 of 00:17.898 (3.78%)
Total events: 374
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.676 (374 / 1) of 00:17.898 (3.78%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:16.366 of 00:17.898 (91.44%)
Total events: 1
Finished in 21.29 seconds (files took 2.1 seconds to load)
1 example, 0 failures
Notes issue note #new_note
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:263
NotificationService
Notes
issue note
#new_note
should eq 0
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.925 of 00:29.388 (6.55%)
Total events: 1783
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:01.925 (1783 / 1) of 00:29.388 (6.55%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:19.271 of 00:29.388 (65.57%)
Total events: 26
Finished in 32.65 seconds (files took 2.09 seconds to load)
1 example, 0 failures
After
Total for these 4 groups: 16 seconds (without the time to load files). This is 6 times faster than before.
Keys
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:181
NotificationService
Keys
#new_key
sends email to key owner
never emails the ghost user
does not send email to key owner
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.570 of 00:01.400 (40.71%)
Total events: 366
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.570 (366 / 2) of 00:01.400 (40.71%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:00.000 of 00:01.400 (0.0%)
Total events: 0
Finished in 5.93 seconds (files took 2.23 seconds to load)
2 examples, 0 failures
GpgKeys
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:202
NotificationService
GpgKeys
#new_gpg_key
sends email to key owner
never emails the ghost user
does not send email to key owner
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.878 of 00:02.539 (34.58%)
Total events: 405
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.878 (405 / 2) of 00:02.539 (34.58%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:00.000 of 00:02.539 (0.0%)
Total events: 0
Finished in 6.45 seconds (files took 2.06 seconds to load)
2 examples, 0 failures
AccessToken
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:223
NotificationService
AccessToken
#access_token_about_to_expire
sends email to the token owner
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:00.472 of 00:01.157 (40.81%)
Total events: 369
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:00.472 (369 / 1) of 00:01.157 (40.81%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:00.000 of 00:01.157 (0.0%)
Total events: 0
Finished in 5.26 seconds (files took 1.99 seconds to load)
1 example, 0 failures
Notes issue note #new_note
› EVENT_PROF='sql.active_record,perform.active_job' bin/rspec -f doc -- spec/services/notification_service_spec.rb:274
NotificationService
Notes
issue note
#new_note
sends emails to recipients
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.399 of 00:04.229 (33.09%)
Total events: 1435
Top 5 slowest suites (by time):
NotificationService (./spec/services/notification_service_spec.rb:5) – 00:01.399 (1435 / 1) of 00:04.229 (33.09%)
[TEST PROF INFO] EventProf results for perform.active_job
Total time: 00:00.000 of 00:04.229 (0.0%)
Total events: 0
Finished in 7.62 seconds (files took 2.21 seconds to load)
1 example, 0 failures
Edited by Rémy Coutable