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

lfs_link_service.rb « lfs_pointers « projects « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e3c956250f02651b4eab19b2ff4b9f683ca694f6 (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
# frozen_string_literal: true

# Given a list of oids, this services links the existent Lfs Objects to the project
module Projects
  module LfsPointers
    class LfsLinkService < BaseService
      # Accept an array of oids to link
      #
      # Returns an array with the oid of the existent lfs objects
      def execute(oids)
        return [] unless project&.lfs_enabled?

        # Search and link existing LFS Object
        link_existing_lfs_objects(oids)
      end

      private

      # rubocop: disable CodeReuse/ActiveRecord
      def link_existing_lfs_objects(oids)
        existent_lfs_objects = LfsObject.where(oid: oids)

        return [] unless existent_lfs_objects.any?

        not_linked_lfs_objects = existent_lfs_objects.where.not(id: project.all_lfs_objects)
        project.all_lfs_objects << not_linked_lfs_objects

        existent_lfs_objects.pluck(:oid)
      end
      # rubocop: enable CodeReuse/ActiveRecord
    end
  end
end