Skip the statistics refresh when nothing transitioned
🤖 AI wrote this code from my instructions.Unreviewed AI output often lands on reviewers and costs them time.
This MR is human verified: I read the full diff and ran the tests myself, because your time is as valuable as mine.
What does this MR do and why?
BaseAutoStateTransitionService#execute schedules Vulnerabilities::Statistics::AdjustmentWorker after every run, whether or not the block transitioned anything. AutoDismissService and AutoResolveService reach it on every pipeline where a policy applies, so a pipeline that changes nothing still enqueues a job.
The third sibling already guards the same call:
| Service | Inherits the base | Guard |
|---|---|---|
AutoDismissService |
yes | none |
AutoResolveService |
yes | none |
AutoSeverityOverrideService |
no, there is a TODO to make it | refresh_statistics if override_count > 0 |
This applies the same condition in the base. If nothing transitioned, the statistics cannot have moved.
Exactly two classes call super do. AutoDismissService initialises @dismissed_count = 0 and AutoResolveService returns .size, so count is always an integer and the comparison is safe.
I have not measured how often the count is zero in production, so the saving is "one Sidekiq job per no-op run" rather than a figure.
References
None.
How to set up and validate locally
bundle exec rspec ee/spec/services/vulnerabilities/auto_resolve_service_spec.rb ee/spec/services/vulnerabilities/auto_dismiss_service_spec.rb115 examples, 0 failures. Reverting the guard alone fails the new example with expected: 0 times with any arguments / received: 1 time.
The sibling service and both workers also stay green:
bundle exec rspec ee/spec/services/vulnerabilities/auto_severity_override_service_spec.rb ee/spec/workers/vulnerabilities/auto_dismiss_worker_spec.rb ee/spec/workers/vulnerabilities/auto_severity_override_worker_spec.rb94 examples, 0 failures.
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.