Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-30 18:08:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-30 18:08:48 +0300
commit340f15b402eec795fca0e0f29709baef0ecf14a7 (patch)
tree6a7eac5d394f4002b9e5b0c9da12bc12e59ed59c /app/services
parent1e254d9f5a46a85c9bb6f24da8265a30fd388db4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/snippets/destroy_service.rb5
-rw-r--r--app/services/snippets/update_statistics_service.rb33
2 files changed, 38 insertions, 0 deletions
diff --git a/app/services/snippets/destroy_service.rb b/app/services/snippets/destroy_service.rb
index 977626fcf17..146a0b53fc1 100644
--- a/app/services/snippets/destroy_service.rb
+++ b/app/services/snippets/destroy_service.rb
@@ -27,6 +27,11 @@ module Snippets
attempt_destroy!
+ # Update project statistics if the snippet is a Project one
+ if snippet.project_id
+ ProjectCacheWorker.perform_async(snippet.project_id, [], [:snippets_size])
+ end
+
ServiceResponse.success(message: 'Snippet was deleted.')
rescue DestroyError
service_response_error('Failed to remove snippet repository.', 400)
diff --git a/app/services/snippets/update_statistics_service.rb b/app/services/snippets/update_statistics_service.rb
new file mode 100644
index 00000000000..61fa43e7755
--- /dev/null
+++ b/app/services/snippets/update_statistics_service.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Snippets
+ class UpdateStatisticsService
+ attr_reader :snippet
+
+ def initialize(snippet)
+ @snippet = snippet
+ end
+
+ def execute
+ unless snippet.repository_exists?
+ return ServiceResponse.error(message: 'Invalid snippet repository', http_status: 400)
+ end
+
+ snippet.repository.expire_statistics_caches
+ statistics.refresh!
+
+ # Update project statistics if the snippet is a Project one
+ if snippet.project_id
+ ProjectCacheWorker.perform_async(snippet.project_id, [], [:snippets_size])
+ end
+
+ ServiceResponse.success(message: 'Snippet statistics successfully updated.')
+ end
+
+ private
+
+ def statistics
+ @statistics ||= snippet.statistics || snippet.build_statistics
+ end
+ end
+end