Skip trace stream loading when coverage regex is absent

What does this MR do and why?

Ci::Build#update_coverage now returns early when coverage_regex is blank instead of calling trace.extract_coverage. This avoids unnecessary work since most builds have no coverage keyword in their CI config.

Before this change, extract_coverage was called unconditionally. Although it returns early when the regex is blank, it first builds the trace stream: loading the job_artifacts_trace association and either opening an archived trace file or constructing a ChunkedIO with an extra query. With the guard clause, none of this overhead runs for builds without a coverage regex, keeping the behavior identical while skipping work.

References

Screenshots or screen recordings

Not applicable, backend-only change.

How to set up and validate locally

  1. In a Rails console, pick a build without a coverage regex and turn on SQL logging:

    build = Ci::Build.where(coverage_regex: nil).last
    ActiveRecord::Base.logger = Logger.new($stdout)
  2. Run the method:

    build.update_coverage # => nil

    Before this change the log shows queries against ci_job_artifacts and ci_build_trace_chunks. After it, no queries run.

  3. Coverage stays nil, as before, since there was no regex to extract with:

    build.coverage # => nil

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.

Edited by Hordur Freyr Yngvason

Merge request reports

Loading
Loading