Skip to content

Topics: add `non_private_projects_count` counter

What does this MR do and why?

This MR is the first step of the issue Explore topics: improve counter consistency (#351115):

  • adds the new non_private_projects_count column (and index) to the Topic model
  • adds a background migration to populate the non_private_projects_count counter
  • adds logic to update the non_private_projects_count counter if a project is saved

The counter is not used yet anywhere. This will happen in a next step of #351115.

🛠 with at Siemens

/cc @bufferoverflow

Migrations

see db:check-migrations job: https://gitlab.com/gitlab-org/gitlab/-/jobs/2022614075

How to set up and validate locally

  1. Create a private project project1.
  2. Visit the project settings and add the topic topic1.
  3. Check counter in Rails console: Projects::Topic.find_by(name: 'topic1').non_private_projects_count should be 0
  4. Visit the project settings and change visibility to public
  5. Check counter in Rails console: Projects::Topic.find_by(name: 'topic1').non_private_projects_count should be 1
  6. Visit the project settings and change visibility to private
  7. Check counter in Rails console: Projects::Topic.find_by(name: 'topic1').non_private_projects_count should be 0
  8. Experiment with adding/removing topics on different project visibility levels.

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 Peter Leitzen

Merge request reports