Read about our upcoming Code of Conduct on this issue

Commit d0dd6d82 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Add helper for accessing lfs_objects for project

This makes accessing LFS Objects for a project easier

  project.lfs_storage_project.lfs_objects`

becomes

  project.all_lfs_objects

This will make the refactor in
https://gitlab.com/gitlab-org/gitlab-ce/issues/39769 easier to deal
with.
parent 052fa32505a7
......@@ -41,7 +41,7 @@ def upload_request?
def existing_oids
@existing_oids ||= begin
storage_project.lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid)
project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid)
end
end
......
......@@ -1066,6 +1066,16 @@ def lfs_storage_project
end
end
# This will return all `lfs_objects` that are accessible to the project.
# So this might be `self.lfs_objects` if the project is not part of a fork
# network, or it is the base of the fork network.
#
# TODO: refactor this to get the correct lfs objects when implementing
# https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
def all_lfs_objects
lfs_storage_project.lfs_objects
end
def personal?
!group
end
......
......@@ -15,8 +15,7 @@ def objects_missing?
return false unless new_lfs_pointers.present?
existing_count = @project.lfs_storage_project
.lfs_objects
existing_count = @project.all_lfs_objects
.where(oid: new_lfs_pointers.map(&:lfs_oid))
.count
......
......@@ -28,7 +28,7 @@ def link_or_create_lfs_object!(path)
lfs_object = LfsObject.find_or_initialize_by(oid: oid, size: size)
lfs_object.file = File.open(path) unless lfs_object.file&.exists?
@project.lfs_storage_project.lfs_objects << lfs_object
@project.all_lfs_objects << lfs_object
end
def lfs_file_paths
......
......@@ -9,9 +9,7 @@ def initialize(project:, shared:)
end
def save
return true if @project.lfs_objects.empty?
@project.lfs_storage_project.lfs_objects.each do |lfs_object|
@project.all_lfs_objects.each do |lfs_object|
save_lfs_object(lfs_object)
end
......
......@@ -2022,6 +2022,22 @@ def create_build(new_pipeline = pipeline, name = 'test')
expect(forked_project.lfs_storage_project).to eq forked_project
end
end
describe '#all_lfs_objects' do
let(:lfs_object) { create(:lfs_object) }
before do
project.lfs_objects << lfs_object
end
it 'returns the lfs object for a project' do
expect(project.all_lfs_objects).to contain_exactly(lfs_object)
end
it 'returns the lfs object for a fork' do
expect(forked_project.all_lfs_objects).to contain_exactly(lfs_object)
end
end
end
describe '#pushes_since_gc' do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment