Optimize factory usage for analytics_merge_request_entity

What does this MR do and why?

This MR replaces create with build_stubbed in ee/spec/serializers/productivity_analytics_merge_request_entity_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 ee/spec/serializers/productivity_analytics_merge_request_entity_spec.rb.

Factory Usage Optimization Results

Before optimization:

  • Factory time: 4.772s (20.67% of total time)

After optimization:

  • Factory time: 0.062s (0.37% of total time)

🚀 Improvement:

  • Factory time reduced by: 4.71s
  • Factory time percentage reduced by: 20.3%
  • Overall factory usage improvement: 98.7%

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
==> Go projects set up in 0.629 seconds...

Test environment set up in 1.9427920000161976 seconds
...[TEST PROF INFO] FactoryDoctor report

Total (potentially) bad examples: 3
Total wasted time: 00:04.378

ProductivityAnalyticsMergeRequestEntity (./ee/spec/serializers/productivity_analytics_merge_request_entity_spec.rb:5) (12 records created, 00:04.378)
  exposes author_avatar_url (./ee/spec/serializers/productivity_analytics_merge_request_entity_spec.rb:20)  4 records created, 00:02.860
  exposes merge_request_url (./ee/spec/serializers/productivity_analytics_merge_request_entity_spec.rb:24)  4 records created, 00:00.711
  exposes all additional metrics (./ee/spec/serializers/productivity_analytics_merge_request_entity_spec.rb:16)  4 records created, 00:00.806




Finished in 16.57 seconds (files took 16.01 seconds to load)
3 examples, 0 failures

Randomized with seed 31146

[TEST PROF INFO] Time spent in factories: 00:04.386 (20.94% of total time)

Factory time after update

[TEST PROF INFO] Time spent in factories: 00:00.062 (0.37% of total time)

This MR also adds the missing feature category in this spec.

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.

Merge request reports

Loading