Class: Gitlab::BackgroundMigration::PopulateProjectSnippetStatistics

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/populate_project_snippet_statistics.rb

Overview

This class creates/updates those project snippets statistics that haven't been created nor initialized. It also updates the related project statistics and its root storage namespace stats

Instance Method Summary collapse

Instance Method Details

#perform(snippet_ids) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/background_migration/populate_project_snippet_statistics.rb', line 9

def perform(snippet_ids)
  project_snippets(snippet_ids).group_by(&:namespace_id).each do |namespace_id, namespace_snippets|
    namespace_snippets.group_by(&:project).each do |project, snippets|
      upsert_snippet_statistics(snippets)
      update_project_statistics(project)
    rescue
      error_message("Error updating statistics for project #{project.id}")
    end

    update_namespace_statistics(namespace_snippets.first.project.root_namespace)
  rescue => e
    error_message("Error updating statistics for namespace #{namespace_id}: #{e.message}")
  end
end