Skip to content

Fix token for repository tree keyset pagination

Vasilii Iakliushin requested to merge 377591_fix_tree_keyset_pagination into master

What does this MR do and why?

Contributes to #377591 (closed)

Problem

The page token generation was done on Rails side before. It used a last element of the collection as a token.

It works for branches and tags, but the tree impementation requires to provide a token from GetTreeEntriesResponse.

Solution

Fetch the cursor from the GetTreeEntriesResponse and correctly assign it to Links header.

Refactor branches and tags finders to have a similar interface as TreeFinder.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
Screenshot_2023-11-10_at_17.55.05 Screenshot_2023-11-10_at_17.48.57

How to set up and validate locally

  1. Enable keyset pagination for tree Feature.enable(:repository_tree_gitaly_pagination)
  2. Find a repository with more than 20 elements (files/directories) in the root directory
  3. Make a call to repository tree API (adjust project id) http://127.0.0.1:3000/api/v4/projects/2/repository/tree?pagination=keyset
  4. You should see a link header in the response with a page_token
  5. Follow the link (something like http://127.0.0.1:3000/api/v4/projects/2/repository/tree?id=2&page=1&page_token=eyJmaWxlX25hbWUiOiJnaXRsYWItZ3JhY2sifQ%3D%3D&pagination=keyset&per_page=20&recursive=false)
  6. You should see the second page of the response

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports