diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /app/models/projects | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'app/models/projects')
-rw-r--r-- | app/models/projects/sync_event.rb | 4 | ||||
-rw-r--r-- | app/models/projects/topic.rb | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/app/models/projects/sync_event.rb b/app/models/projects/sync_event.rb index 5221b00c55f..7af863c0cf0 100644 --- a/app/models/projects/sync_event.rb +++ b/app/models/projects/sync_event.rb @@ -13,4 +13,8 @@ class Projects::SyncEvent < ApplicationRecord def self.enqueue_worker ::Projects::ProcessSyncEventsWorker.perform_async # rubocop:disable CodeReuse/Worker end + + def self.upper_bound_count + select('COALESCE(MAX(id) - MIN(id) + 1, 0) AS upper_bound_count').to_a.first.upper_bound_count + end end diff --git a/app/models/projects/topic.rb b/app/models/projects/topic.rb index 8d6f8c3a9ca..78bc2df2e1e 100644 --- a/app/models/projects/topic.rb +++ b/app/models/projects/topic.rb @@ -25,6 +25,29 @@ module Projects def search(query) fuzzy_search(query, [:name]) end + + def update_non_private_projects_counter(ids_before, ids_after, project_visibility_level_before, project_visibility_level_after) + project_visibility_level_before ||= project_visibility_level_after + + topics_to_decrement = [] + topics_to_increment = [] + topic_ids_removed = ids_before - ids_after + topic_ids_retained = ids_before & ids_after + topic_ids_added = ids_after - ids_before + + if project_visibility_level_before > Gitlab::VisibilityLevel::PRIVATE + topics_to_decrement += topic_ids_removed + topics_to_decrement += topic_ids_retained if project_visibility_level_after == Gitlab::VisibilityLevel::PRIVATE + end + + if project_visibility_level_after > Gitlab::VisibilityLevel::PRIVATE + topics_to_increment += topic_ids_added + topics_to_increment += topic_ids_retained if project_visibility_level_before == Gitlab::VisibilityLevel::PRIVATE + end + + where(id: topics_to_increment).update_counters(non_private_projects_count: 1) unless topics_to_increment.empty? + where(id: topics_to_decrement).where('non_private_projects_count > 0').update_counters(non_private_projects_count: -1) unless topics_to_decrement.empty? + end end end end |