Backport of 'Skip code navigation lookups when a project has no LSIF artifacts' into 19.5
What does this MR do and why?
Backport of !264106 (merged) into 19.5. 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 today, so !267752 (merged) backports this into 19.4. This MR covers 19.5, which the tenant moves to under the Dedicated N-1 schedule, so the fix is not lost when they step up a minor version.
- Zendesk 752368
- gitlab-com/request-for-help#5424
Cherry-pick notes
Applied cleanly. Both 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.
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
- severity label and bug subtype labels (if applicable)
- If this MR fixes a bug that affects customers, the customer label has been applied.
- This MR has been approved by a maintainer (only one approval is required).
- Ensure the
E2E Omnibus GitLab EEpipeline (triggered by thee2e:test-on-omnibus-eejob) 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:
- Refer to the patch release runbook for engineers and maintainers for guidance.
- Ask questions on the
#releasesSlack channel (internal only). - Once the backport has been merged, the commit changes will be automatically deployed to a release environment that can be used for manual validation. See after merging runbook for details.
cc @tigerwnz