Remove unwanted refs after importing a project
Because we don't need them, and they would slow down the repository, keeping unneeded objects as well. We could also consider doing this in regular housekeeping.
This commit is contained in:
parent
d546f7d36e
commit
5f811894a8
3 changed files with 36 additions and 1 deletions
|
@ -372,7 +372,7 @@ class Project < ActiveRecord::Base
|
|||
if Gitlab::ImportSources.importer_names.include?(project.import_type) && project.repo_exists?
|
||||
project.run_after_commit do
|
||||
begin
|
||||
Projects::HousekeepingService.new(project).execute
|
||||
Projects::ImportExport::CleanupService.new(project).execute
|
||||
rescue Projects::HousekeepingService::LeaseTaken => e
|
||||
Rails.logger.info("Could not perform housekeeping for project #{project.full_path} (#{project.id}): #{e}")
|
||||
end
|
||||
|
|
|
@ -26,6 +26,8 @@ module Projects
|
|||
lease_uuid = try_obtain_lease
|
||||
raise LeaseTaken unless lease_uuid.present?
|
||||
|
||||
yield if block_given?
|
||||
|
||||
execute_gitlab_shell_gc(lease_uuid)
|
||||
end
|
||||
|
||||
|
|
33
app/services/projects/import_export/cleanup_service.rb
Normal file
33
app/services/projects/import_export/cleanup_service.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Projects
|
||||
module ImportExport
|
||||
class CleanupService
|
||||
RESERVED_REFS_REGEXP =
|
||||
%r{\Arefs/(?:heads|tags|merge\-requests|keep\-around|environments)/}
|
||||
|
||||
attr_reader :project
|
||||
|
||||
def initialize(project)
|
||||
@project = project
|
||||
end
|
||||
|
||||
# This could raise Projects::HousekeepingService::LeaseTaken
|
||||
def execute
|
||||
Projects::HousekeepingService.new(project).execute do
|
||||
garbage_refs.each(&rugged.references.method(:delete))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def garbage_refs
|
||||
@garbage_refs ||= rugged.references.reject do |ref|
|
||||
ref.name =~ RESERVED_REFS_REGEXP
|
||||
end
|
||||
end
|
||||
|
||||
def rugged
|
||||
@rugged ||= project.repository.rugged
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue