Commit 5f811894 authored by Lin Jen-Shin's avatar Lin Jen-Shin

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.
parent d546f7d3
......@@ -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
......
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
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