Class: Projects::ContainerRepository::CleanupTagsService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility, Gitlab::Utils::StrongMemoize
Defined in:
app/services/projects/container_repository/cleanup_tags_service.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(container_repository, user = nil, params = {}) ⇒ CleanupTagsService

Returns a new instance of CleanupTagsService.


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/projects/container_repository/cleanup_tags_service.rb', line 9

def initialize(container_repository, user = nil, params = {})
  @container_repository = container_repository
  @current_user = user
  @params = params.dup

  @project = container_repository.project
  @tags = container_repository.tags
  tags_size = @tags.size
  @counts = {
    original_size: tags_size,
    cached_tags_count: 0
  }
end

Instance Method Details

#executeObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/projects/container_repository/cleanup_tags_service.rb', line 23

def execute
  return error('access denied') unless can_destroy?
  return error('invalid regex') unless valid_regex?

  filter_out_latest
  filter_by_name

  truncate
  populate_from_cache

  filter_keep_n
  filter_by_older_than

  delete_tags.merge(@counts).tap do |result|
    result[:before_delete_size] = @tags.size
    result[:deleted_size] = result[:deleted]&.size

    result[:status] = :error if @counts[:before_truncate_size] != @counts[:after_truncate_size]
  end
end