-
- Downloads
Eliminate Gitaly N+1 queries with notes API
Similar to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31834, we see that in https://gitlab.com/gitlab-org/gitlab-ce/issues/65957 there can be hundreds, even thousands, of Gitaly requests in the `/api/:version/projects/:id/merge_requests/:noteable_id/notes` endpoint. Previously, the API to retrieve notes generated hundreds of Gitaly calls to determine whether a system note should be shown to the user. It did this by: 1. Rendering the Markdown 2. Extracting cross-references from the Markdown 3. Issuing a Gitaly `FindCommit` RPC for every reference to validate that the commit exists. The last step is unnecessary because we don't need to display a commit if the user doesn't have access to the project in the first place. `RendersNotes#prepare_notes_for_rendering` is already used in `MergeRequestsController`, which is why we don't see N+1 Gitaly calls there. We use it here to optimize the note redaction process.
Showing
- changelogs/unreleased/sh-eliminate-gitaly-nplus-one-notes.yml 5 additions, 0 deletions...gelogs/unreleased/sh-eliminate-gitaly-nplus-one-notes.yml
- lib/api/helpers/notes_helpers.rb 2 additions, 0 deletionslib/api/helpers/notes_helpers.rb
- lib/api/notes.rb 7 additions, 6 deletionslib/api/notes.rb
- spec/requests/api/discussions_spec.rb 3 additions, 51 deletionsspec/requests/api/discussions_spec.rb
- spec/requests/api/notes_spec.rb 7 additions, 0 deletionsspec/requests/api/notes_spec.rb
- spec/support/shared_examples/requests/api/discussions.rb 54 additions, 0 deletionsspec/support/shared_examples/requests/api/discussions.rb
Please register or sign in to comment