Fix token for repository tree keyset pagination
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 |
---|---|
How to set up and validate locally
- Enable keyset pagination for tree
Feature.enable(:repository_tree_gitaly_pagination)
- Find a repository with more than 20 elements (files/directories) in the root directory
- Make a call to repository tree API (adjust project id) http://127.0.0.1:3000/api/v4/projects/2/repository/tree?pagination=keyset
- You should see a link header in the response with a
page_token
- 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
) - 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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Vasilii Iakliushin