Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cleanup_service.rb « gitaly_client « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c2c41a244ec3e462475f6cdf871e5b0350915a7 (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
# frozen_string_literal: true

module Gitlab
  module GitalyClient
    class CleanupService
      include WithFeatureFlagActors

      attr_reader :repository, :gitaly_repo, :storage

      # 'repository' is a Gitlab::Git::Repository
      def initialize(repository)
        @repository = repository
        @gitaly_repo = repository.gitaly_repository
        @storage = repository.storage

        self.repository_actor = repository
      end

      def apply_bfg_object_map_stream(io, &blk)
        response = gitaly_client_call(
          storage,
          :cleanup_service,
          :apply_bfg_object_map_stream,
          build_object_map_enum(io),
          timeout: GitalyClient.long_timeout
        )
        response.each(&blk)
      end

      private

      def build_object_map_enum(io)
        Enumerator.new do |y|
          # First request. For simplicity, doesn't include any object map data
          y << Gitaly::ApplyBfgObjectMapStreamRequest.new(repository: gitaly_repo)

          # Now stream the BFG object map file to gitaly in chunks
          while data = io.read(RepositoryService::MAX_MSG_SIZE)
            y << Gitaly::ApplyBfgObjectMapStreamRequest.new(object_map: data)

            break if io&.eof?
          end
        end
      end
    end
  end
end