diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/services/projects/update_statistics_service.rb | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/services/projects/update_statistics_service.rb')
-rw-r--r-- | app/services/projects/update_statistics_service.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/app/services/projects/update_statistics_service.rb b/app/services/projects/update_statistics_service.rb index a0793cff2df..71f5a8e633d 100644 --- a/app/services/projects/update_statistics_service.rb +++ b/app/services/projects/update_statistics_service.rb @@ -2,18 +2,49 @@ module Projects class UpdateStatisticsService < BaseService + include ::Gitlab::Utils::StrongMemoize + + STAT_TO_CACHED_METHOD = { + repository_size: :size, + commit_count: :commit_count + }.freeze + def execute return unless project Gitlab::AppLogger.info("Updating statistics for project #{project.id}") - project.statistics.refresh!(only: statistics.map(&:to_sym)) + expire_repository_caches + expire_wiki_caches + project.statistics.refresh!(only: statistics) end private + def expire_repository_caches + if statistics.empty? + project.repository.expire_statistics_caches + elsif method_caches_to_expire.present? + project.repository.expire_method_caches(method_caches_to_expire) + end + end + + def expire_wiki_caches + return unless project.wiki_enabled? && statistics.include?(:wiki_size) + + project.wiki.repository.expire_method_caches([:size]) + end + + def method_caches_to_expire + strong_memoize(:method_caches_to_expire) do + statistics.map { |stat| STAT_TO_CACHED_METHOD[stat] }.compact + end + end + def statistics - params[:statistics] + strong_memoize(:statistics) do + params[:statistics]&.map(&:to_sym) + end end end end |