GitHub import: Run housekeeping after initial import

After an initial fetch, the repository will have many loose objects
and refs. Running a `git gc` will compact refs into `packed-refs` and
objects into `.pack` files, which should make importing pull
requests faster.

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/59477
This commit is contained in:
Stan Hu 2019-03-26 09:26:12 -05:00
parent 33316f7f17
commit d7c1bed80d
3 changed files with 15 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
title: 'GitHub import: Run housekeeping after initial import'
merge_request: 26600
author:
type: performance

View file

@ -54,6 +54,11 @@ module Gitlab
project.repository.fetch_as_mirror(project.import_url, refmap: refmap, forced: true, remote_name: 'github') project.repository.fetch_as_mirror(project.import_url, refmap: refmap, forced: true, remote_name: 'github')
project.change_head(default_branch) if default_branch project.change_head(default_branch) if default_branch
# The initial fetch can bring in lots of loose refs and objects.
# Running a `git gc` will make importing pull requests faster.
Projects::HousekeepingService.new(project, :gc).execute
true true
rescue Gitlab::Git::Repository::NoRepository, Gitlab::Shell::Error => e rescue Gitlab::Git::Repository::NoRepository, Gitlab::Shell::Error => e
fail_import("Failed to import the repository: #{e.message}") fail_import("Failed to import the repository: #{e.message}")

View file

@ -197,6 +197,11 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
.to receive(:fetch_as_mirror) .to receive(:fetch_as_mirror)
.with(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true, remote_name: 'github') .with(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true, remote_name: 'github')
service = double
expect(Projects::HousekeepingService)
.to receive(:new).with(project, :gc).and_return(service)
expect(service).to receive(:execute)
expect(importer.import_repository).to eq(true) expect(importer.import_repository).to eq(true)
end end