Investigate if latest_build_for_default_branch is causing extra queries

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Topic to Evaluate

The following discussion from !109723 (merged) should be addressed:

Q: Why don't we always take a SBOM generation job from SbomScanner.latest_pipeline(project, project.default_branch)?

  • Is that for efficiency, to avoid unnecessary queries?
  • Is that for accuracy, in a scenario where we should return the pipeline as long as it's for the default branch, and even if it's not the latest? When would that happen?

If this is for efficiency (to avoid extra queries) but it adds to the complexity of the implementation and it can't be easily tested, then I suggest we iterate:

This context is related to this proposed change:

      def latest_build_for_default_branch
        if !pipeline.blank? && pipeline.default_branch?
          pipeline.builds.latest.sbom_generation.last
        else
          pipeline = self.class.latest_pipeline(project, project.default_branch)

          return if pipeline.blank?

          pipeline.builds.latest.sbom_generation.last
        end
      end
      strong_memoize_attr :latest_build_for_default_branch

Tasks prior to evaluation

  • Clearly document the topic to evaluated in this issue description
  • Determine specific scope including time-bounds for investigation

Tasks to Evaluate

  • Does calling pipeline.default_branch? trigger a query?
  • Is it common enough for a pipeline from a non-default branch to be used by the scanners that this optimization warrants the increase in complexity?
  • Create issue for implementation or update existing implementation issue description with implementation proposal
  • Set weight on implementation issue
  • If weight is greater than 5, break issue into smaller issues

Proposal

Investigate if always fetching the latest pipeline for the default branch impacts performance because of an extra query.

Risks and Implementation Considerations

Team

Edited by 🤖 GitLab Bot 🤖