Skip to content

Remove 2N find_commit calls from Projects::BranchesController#index

Takuya Noguchi requested to merge 22851-reduce-2n-plus-1-gitaly-to-n-plus-1 into master

What does this MR do?

Removes unnecessary 2N-times Gitlab::GitalyClient::CommitService#find_commit calls via EE::Repository#diverged_from_upstream? from Projects::BranchesController#index only for a mirrored and/or forked project by delegating Gitlab::GitalyClient::CommitService#ancestor? to resolve branch ref to commit ID (SHA-1). This reduces 3N+1 gitaly calls to N+1 calls.

They are not required to check if a branch is diverged from upstream as git-merge-base and its Gitaly CommitIsAncestor func both support ref strings as argument.

~backstage: This also removes EE::Repository#upstream_has_diverged?, which was originally introduced in !249 (merged) (and re-organized in !6583 (merged)), but after !2919 (merged) (%10.1) through 12.8, we have never used it any more.

This updates !8495 (merged) (cf. gitlab-foss#50843 (closed)) as we do not have to make EE::Repository#commit call any more with this MR.

Calls before the MR

  • 2N Gitlab::GitalyClient::CommitService#find_commit calls (N calls for refs/heads/BRANCH_NAME, yet other N calls for refs/remotes/upstream/BRANCH_NAME)
  • 0...N Gitlab::GitalyClient::CommitService#ancestor? calls

Calls after the MR

  • N Gitlab::GitalyClient::CommitService#ancestor? calls
  • 0 Gitlab::GitalyClient::CommitService#find_commit calls

References

Parts of #22851

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [n/a] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [n/a] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [n/a] Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading