Skip to content

Repository default branch change not reflected until clearing cache

What does this MR do and why?

This MR adds the project's default_branch to the cache_context in /projects/:id/repository/branches to invalidate the cache after 30 seconds instead of 60 minutes to visualize changes when the project's default branch changes to another branch.

This bug affects both the UI dropdown and the API results.

MR acceptance checklist

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

How to set up and validate locally

Before

  1. Create a repository and add a branch (main, another)
  2. Update the Default Branch (Settings > Repository) to the new branch.
  3. View Repository dropdown or query API to confirm the issue.

API call to List repository branches will also show the previous setting, and not reflect the current state. https://docs.gitlab.com/ee/api/branches.html#list-repository-branches

curl -X GET -H "Accept: application/json" -H "Private-Token: TOKEN_TOKEN" "https://gitlab.com/api/v4/projects/52396192/repository/branches"

[
  {
    "name": "another",
    ...
    "default": false,
  },
  {
    "name": "main",
    ...
    "default": true,
  }
]

The default branch in the dropdown should change after 60 minutes or after trigger sudo gitlab-rake cache:clear.

After

Repeat the same steps in this branch. The default branch should change to the new one after 30 seconds.

Related to #432626 (closed)

Edited by Javiera Tapia

Merge request reports