diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-04 03:11:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-04 03:11:19 +0300 |
commit | b3930fc34f7ed725bb79fc0ec563602ed20d879b (patch) | |
tree | 086bd7237ad86cf778c773cfa512763bc5dd8567 /lib/gitlab/cleanup | |
parent | 63b3a14f15ee5c202d78b7bd72030f4f437ef982 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cleanup')
-rw-r--r-- | lib/gitlab/cleanup/redis/batch_delete_by_pattern.rb | 49 | ||||
-rw-r--r-- | lib/gitlab/cleanup/redis/description_templates_cache_keys_pattern_builder.rb | 88 |
2 files changed, 0 insertions, 137 deletions
diff --git a/lib/gitlab/cleanup/redis/batch_delete_by_pattern.rb b/lib/gitlab/cleanup/redis/batch_delete_by_pattern.rb deleted file mode 100644 index 8f3b73c7b0e..00000000000 --- a/lib/gitlab/cleanup/redis/batch_delete_by_pattern.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Cleanup - module Redis - class BatchDeleteByPattern - REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000 - REDIS_SCAN_START_STOP = '0'.freeze # Magic value, see http://redis.io/commands/scan - - attr_reader :patterns - - def initialize(patterns) - raise ArgumentError.new('Argument should be an Array of patterns') unless patterns.is_a?(Array) - - @patterns = patterns - end - - def execute - return if patterns.blank? - - batch_delete_cache_keys - end - - private - - def batch_delete_cache_keys - Gitlab::Redis::Cache.with do |redis| - patterns.each do |match| - cursor = REDIS_SCAN_START_STOP - loop do - cursor, keys = redis.scan( - cursor, - match: match, - count: REDIS_CLEAR_BATCH_SIZE - ) - - Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do - redis.del(*keys) if keys.any? - end - - break if cursor == REDIS_SCAN_START_STOP - end - end - end - end - end - end - end -end diff --git a/lib/gitlab/cleanup/redis/description_templates_cache_keys_pattern_builder.rb b/lib/gitlab/cleanup/redis/description_templates_cache_keys_pattern_builder.rb deleted file mode 100644 index 6d16f6c1e00..00000000000 --- a/lib/gitlab/cleanup/redis/description_templates_cache_keys_pattern_builder.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Cleanup - module Redis - class DescriptionTemplatesCacheKeysPatternBuilder - # project_ids - a list of project_ids for which to compute description templates cache keys or `:all` to compute - # a pattern that cover all description templates cache keys. - # - # Example - # * ::Gitlab::Cleanup::Redis::BatchDeleteDescriptionTemplates.new(:all).execute - to get 2 - # patterns for all issue and merge request description templates cache keys. - # - # * ::Gitlab::Cleanup::Redis::BatchDeleteDescriptionTemplates.new([1,2,3,4]).execute - to get an array of - # patterns for each project's issue and merge request description templates cache keys. - def initialize(project_ids) - raise ArgumentError.new('project_ids can either be an array of project IDs or :all') if project_ids != :all && !project_ids.is_a?(Array) - - @project_ids = parse_project_ids(project_ids) - end - - def execute - case project_ids - when :all - all_instance_patterns - else - project_patterns - end - end - - private - - attr_reader :project_ids - - def parse_project_ids(project_ids) - return project_ids if project_ids == :all - - project_ids.map { |id| Integer(id) } - rescue ArgumentError - raise ArgumentError.new('Invalid Project ID. Please ensure all passed in project ids values are valid integer project ids.') - end - - def project_patterns - cache_key_patterns = [] - Project.id_in(project_ids).each_batch do |batch| - cache_key_patterns << batch.map do |pr| - next unless pr.repository.exists? - - cache = Gitlab::RepositoryCache.new(pr.repository) - - [repo_issue_templates_cache_key(cache), repo_merge_request_templates_cache_key(cache)] - end - end - - cache_key_patterns.flatten.compact - end - - def all_instance_patterns - [all_issue_templates_cache_key, all_merge_request_templates_cache_key] - end - - def issue_templates_cache_key - Repository::METHOD_CACHES_FOR_FILE_TYPES[:issue_template] - end - - def merge_request_templates_cache_key - Repository::METHOD_CACHES_FOR_FILE_TYPES[:merge_request_template] - end - - def all_issue_templates_cache_key - "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{issue_templates_cache_key}:*" - end - - def all_merge_request_templates_cache_key - "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{merge_request_templates_cache_key}:*" - end - - def repo_issue_templates_cache_key(cache) - "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{cache.cache_key(issue_templates_cache_key)}" - end - - def repo_merge_request_templates_cache_key(cache) - "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{cache.cache_key(merge_request_templates_cache_key)}" - end - end - end - end -end |