Optimize factory usage for search service presenter
What does this MR do and why?
This MR replaces create with build_stubbed in spec/presenters/search_service_presenter_spec.rb to optimize the factory usage as recommended in our handbook.
This spec is part of the list .rubocop_todo/rspec/factory_bot/avoid_create.yml.
It was verified that database persistence is not needed using the factory doctor command FDOC=1 bin/rspec spec/presenters/search_service_presenter_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 0.729s (4.2% of total time)
After optimization:
- Factory time: 0.006s (0.04% of total time)
- Factory time reduced by: 0.723s
- Factory time percentage reduced by: 4.16%
- Overall factory usage improvement: 99.2%
Factory Doctor Output
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
==> Using precompiled Gitaly binaries from cache
Test environment set up in 0.9921340000000782 seconds
.......[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 5
Total wasted time: 00:00.214
SearchServicePresenter (./spec/presenters/search_service_presenter_spec.rb:5) (10 records created, 00:00.214)
is expected to eq false (./spec/presenters/search_service_presenter_spec.rb:58) – 2 records created, 00:00.046
is expected to eq true (./spec/presenters/search_service_presenter_spec.rb:51) – 2 records created, 00:00.039
is expected to eq true (./spec/presenters/search_service_presenter_spec.rb:51) – 2 records created, 00:00.049
is expected to eq true (./spec/presenters/search_service_presenter_spec.rb:51) – 2 records created, 00:00.039
is expected to eq false (./spec/presenters/search_service_presenter_spec.rb:51) – 2 records created, 00:00.038
Finished in 13.21 seconds (files took 14.04 seconds to load)
7 examples, 0 failures
Randomized with seed 23910
[TEST PROF INFO] Time spent in factories: 00:00.741 (4.35% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.006 (0.04% of total time)
References
Relates to: #378910.
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.