Commit 48b17e99 authored by Bob Van Landuyt's avatar Bob Van Landuyt

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 10d0f438
......@@ -41,7 +41,7 @@ class Projects::LfsApiController < Projects::GitHttpClientController
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 @@ class Project < ActiveRecord::Base
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 @@ module Gitlab
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 @@ module Gitlab
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 @@ module Gitlab
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 @@ describe Project do
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