Backport of 'Skip code navigation lookups when a project has no LSIF artifacts' into 19.4

What does this MR do and why?

Backport of !264106 (merged) into 19.4. Cherry-pick of a69606f25d663a931cf67073f06f88815e225acc.

Gitlab::CodeNavigationPath#build runs on the blob page and on every merge request diff render. It queries every pipeline of the latest commit shas, including for projects that never produced an LSIF artifact and can therefore never render code navigation. On a project where one commit has collected tens of thousands of pipelines, that lookup reads all of them: the only sha index on p_ci_pipelines is (project_id, sha) without id, so Postgres estimates a single row and heap fetches the rest. Database Lab measured 38.9 s cold and 282 MiB for the equivalent lookup.

This change adds an early guard. When the project has no LSIF artifacts, it skips the Gitaly commit lookup and the pipeline lookup and returns nil. The existence check is an index-only LIMIT 1 query and the result is memoized for the rest of the request.

Three files, +12 / -0. No migration, no schema change, no new query shape.

Why backport

Reported by a GitLab Dedicated customer whose blob and README views return 500 on an affected project. The tenant runs 19.4.3 and is scheduled to 19.4.5, so it cannot receive this from master. A matching backport into 19.5 is raised in !267753 (merged) to cover the tenant's upgrade path.

  • Zendesk 752368
  • gitlab-com/request-for-help#5424

Cherry-pick notes

Applied cleanly. lib/gitlab/code_navigation_path.rb and spec/lib/gitlab/code_navigation_path_spec.rb are byte-identical to master on this branch apart from this change. The allowed: block of scripts/database/query_analyzers.yml is also identical; the two branches differ only in the todos: block, which this change does not touch.

Squash is disabled so the Changelog: performance trailer and the (cherry picked from commit ...) line survive the merge.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
  • The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes).
  • The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
  • Required labels have been applied to this merge request
  • This MR has been approved by a maintainer (only one approval is required).
  • Ensure the E2E Omnibus GitLab EE pipeline (triggered by thee2e:test-on-omnibus-ee job) has succeeded. If it has failed (or shows warnings), investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.

Note to the merge request author and maintainer

If you have questions about the patch release process, please:

cc @tigerwnz

Edited by Anthony Suchodolski

Merge request reports

Loading
Loading