Optimize factory usage for analytics build entity

What does this MR do and why?

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

Factory Usage Optimization Results

Before optimization:

  • Factory time: 8.086s (10.64% of total time)

After optimization:

  • Factory time: 0.161s (0.91% of total time)

🚀 Improvement:

  • Factory time reduced by: 7.925s
  • Factory time percentage reduced by: 9.73%
  • Overall factory usage improvement: 98.0%

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 1.2387719999969704 seconds
................[TEST PROF INFO] FactoryDoctor report

Total (potentially) bad examples: 16
Total wasted time: 00:07.333

AnalyticsBuildEntity (./spec/serializers/analytics_build_entity_spec.rb:5) (112 records created, 00:07.333)
  contains the URL (./spec/serializers/analytics_build_entity_spec.rb:22)  7 records created, 00:01.726
  contains the author (./spec/serializers/analytics_build_entity_spec.rb:26)  7 records created, 00:00.334
  contains the project path (./spec/serializers/analytics_build_entity_spec.rb:30)  7 records created, 00:00.540
  contains the namespace full path (./spec/serializers/analytics_build_entity_spec.rb:34)  7 records created, 00:00.309
  does not contain sensitive information (./spec/serializers/analytics_build_entity_spec.rb:38)  7 records created, 00:00.307
  contains the right started at (./spec/serializers/analytics_build_entity_spec.rb:43)  7 records created, 00:00.538
  contains the duration (./spec/serializers/analytics_build_entity_spec.rb:47)  7 records created, 00:00.309
  does not blow up (./spec/serializers/analytics_build_entity_spec.rb:55)  7 records created, 00:00.325
  shows the right message (./spec/serializers/analytics_build_entity_spec.rb:59)  7 records created, 00:00.324
  shows the right total time (./spec/serializers/analytics_build_entity_spec.rb:63)  7 records created, 00:00.517
  does not blow up (./spec/serializers/analytics_build_entity_spec.rb:71)  7 records created, 00:00.323
  shows the right message (./spec/serializers/analytics_build_entity_spec.rb:75)  7 records created, 00:00.301
  shows the right total time (./spec/serializers/analytics_build_entity_spec.rb:79)  7 records created, 00:00.315
  does not blow up (./spec/serializers/analytics_build_entity_spec.rb:87)  7 records created, 00:00.318
  shows the right message (./spec/serializers/analytics_build_entity_spec.rb:91)  7 records created, 00:00.306
  shows the right total time (./spec/serializers/analytics_build_entity_spec.rb:95)  7 records created, 00:00.533




Finished in 19.1 seconds (files took 16.46 seconds to load)
16 examples, 0 failures

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

Factory time before the update

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

Factory time after update

[TEST PROF INFO] Time spent in factories: 00:00.161 (0.91% 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