Class: Packages::UpdateTagsService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/update_tags_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(package, tags = []) ⇒ UpdateTagsService

Returns a new instance of UpdateTagsService.



6
7
8
9
# File 'app/services/packages/update_tags_service.rb', line 6

def initialize(package, tags = [])
  @package = package
  @tags = tags
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
# File 'app/services/packages/update_tags_service.rb', line 11

def execute
  return if @tags.empty?

  tags_to_destroy = existing_tags - @tags
  tags_to_create = @tags - existing_tags

  @package.tags.with_name(tags_to_destroy).delete_all if tags_to_destroy.any?
  ::ApplicationRecord.legacy_bulk_insert(Packages::Tag.table_name, rows(tags_to_create)) if tags_to_create.any? # rubocop:disable Gitlab/BulkInsert
end