Gitaly page-token pagination for protected_tags and protected_branches
Problem to solve
After adding the pagination_params to the list_refs Gitaly call in Add support for pagination to Gitlab::Git::Find... (!197797 - merged), the response includes only the first 20 protected_tags or protected_branches that match the search term. This is blocking Strong memoize tag_names and branch_names in re... (!200286 - merged) since we need to use the Gitlab::Git::Finders::RefsFinder finder.
Replication of the problem
The Lab Coat project has 57 tags locally:
[25] pry(main)> project = Project.find_by_name("Lab Coat")
=> #<Project id:12 may/lab-coat>>
[26] pry(main)> project.repository.tag_names.count
=> 57
By using Gitlab::Git::Finders::RefsFinder, it returns only the first 20 records.
[9] pry(main)> project = Project.find_by_name("Lab Coat")
=> #<Project id:12 may/lab-coat>>
[10] pry(main)> finder = Gitlab::Git::Finders::RefsFinder.new(project.repository.raw_repository, ref_type: :tags)
=> #<Gitlab::Git::Finders::RefsFinder:0x000000016fd5aaa0
@page_token=nil,
@per_page=nil,
@ref_type=:tags,
@repository=
#<Gitlab::Git::Repository:0x000000016fd5bae0
@container=#<Project id:12 may/lab-coat>>,
@gl_project_path="may/lab-coat",
@gl_repository="project-12",
@name="6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918.git",
@relative_path="@hashed/6b/51/6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918.git",
@storage="default">,
@search=nil,
@sort_by=nil>
[11] pry(main)> finder.execute.size
=> 20
[12] pry(main)>
What does this MR do and why?
Summarized code changed by Duo
-
This change improves how GitLab displays lists of protected branches and tags by adding pagination support. Previously, when viewing protected branches or tags that matched certain patterns, all results would load at once, which could be slow for projects with many branches/tags.
-
The update introduces a new service that uses a faster "page-token" approach (using Gitaly RPC) for moving forward through results.
-
The code also fixes how branch and tag names are displayed by properly removing internal Git prefixes (like "refs/heads/" for branches) so users see cleaner names. Additionally, it adds navigation controls to the web interface, allowing users to move between pages of results with "next" link.
-
The changes include comprehensive tests to ensure the pagination works correctly in various scenarios, such as when there are no matching results or when users provide invalid page numbers. Overall, this makes the protected branches and tags pages more responsive and user-friendly, especially for large projects.
Screenshots or screen recordings
Protected tags pagination
Screen_Recording_2025-08-13_at_11.44.54_AM
Protected branches pagination
Screen_Recording_2025-08-13_at_11.46.16_AM
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.
Related to #559195 (closed)