Use Gitlab::Git::Finders::BranchesFinder in branches API

What does this MR do and why?

Contributes to #578546

Problem

The branches API endpoint uses BranchesFinder which fetches all branches from Gitaly and then filters/sorts them in Ruby. This is inefficient for large repositories with many branches.

Solution

Wire up Gitlab::Git::Finders::BranchesFinder in the branches API behind the use_new_branches_finder_api feature flag. The new finder delegates search, sort, and pagination to Gitaly via RefsFinder, avoiding fetching all branches into memory.

Update GitalyKeysetPager to handle the new finder which always paginates via Gitaly and does not accept the gitaly_pagination: keyword argument.

Fall back to the old BranchesFinder when the feature flag is disabled or when the regex parameter is used, since the new finder only supports glob-based searching.

References

Screenshots or screen recordings

Not applicable — no UI changes.

How to set up and validate locally

  1. Enable the feature flag: Feature.enable(:use_new_branches_finder_api)
  2. Make an API request: http://gdk.test:3000/api/v4/projects/1/repository/branches?per_page=5
  3. Verify branches are returned with correct commit data
  4. Test with search: http://gdk.test:3000/api/v4/projects/1/repository/branches?per_page=5&search=mast
  5. Test regex fallback: http://gdk.test:3000/api/v4/projects/1/repository/branches?per_page=5&regex=feat.*
  6. Disable the flag and verify the old BranchesFinder is used

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports

Loading