Class: Gitlab::Composer::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/composer/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(project:, name:, last_page_sha: nil) ⇒ Cache

Returns a new instance of Cache.



8
9
10
11
12
# File 'lib/gitlab/composer/cache.rb', line 8

def initialize(project:, name:, last_page_sha: nil)
  @project = project
  @name = name
  @last_page_sha = last_page_sha
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/composer/cache.rb', line 14

def execute
  Packages::Composer::Metadatum.transaction do # rubocop: disable CodeReuse/ActiveRecord
    # make sure we lock these records at the start
    

    if .any?
      mark_pages_for_delete(shas_to_delete)

      create_cache_page!

      # assign the newest page SHA to the packages
      .update_all(version_cache_sha: version_index.sha)
    elsif @last_page_sha
      mark_pages_for_delete([@last_page_sha])
    end
  end
end