summaryrefslogtreecommitdiff
path: root/lib/gitlab/github_import/importer/releases_attachments_importer.rb
blob: 7221c802d83904b660fc4ad39ce28fe78f0415d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Importer
      class ReleasesAttachmentsImporter
        include ParallelScheduling

        BATCH_SIZE = 100

        # The method that will be called for traversing through all the objects to
        # import, yielding them to the supplied block.
        def each_object_to_import
          project.releases.select(:id, :description).each_batch(of: BATCH_SIZE, column: :id) do |batch|
            batch.each do |release|
              next if already_imported?(release)

              Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)

              yield release

              # We mark the object as imported immediately so we don't end up
              # scheduling it multiple times.
              mark_as_imported(release)
            end
          end
        end

        def representation_class
          Representation::ReleaseAttachments
        end

        def importer_class
          ReleaseAttachmentsImporter
        end

        def sidekiq_worker_class
          ImportReleaseAttachmentsWorker
        end

        def collection_method
          :release_attachments
        end

        def object_type
          :release_attachment
        end

        def id_for_already_imported_cache(release)
          release.id
        end

        def object_representation(object)
          representation_class.from_db_record(object)
        end
      end
    end
  end
end