From d7c1bed80d55611ca297c5c7664658d1144c5a85 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 26 Mar 2019 09:26:12 -0500 Subject: 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 --- changelogs/unreleased/sh-git-gc-after-initial-fetch.yml | 5 +++++ lib/gitlab/github_import/importer/repository_importer.rb | 5 +++++ spec/lib/gitlab/github_import/importer/repository_importer_spec.rb | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 changelogs/unreleased/sh-git-gc-after-initial-fetch.yml diff --git a/changelogs/unreleased/sh-git-gc-after-initial-fetch.yml b/changelogs/unreleased/sh-git-gc-after-initial-fetch.yml new file mode 100644 index 00000000000..867d7e6b9df --- /dev/null +++ b/changelogs/unreleased/sh-git-gc-after-initial-fetch.yml @@ -0,0 +1,5 @@ +--- +title: 'GitHub import: Run housekeeping after initial import' +merge_request: 26600 +author: +type: performance diff --git a/lib/gitlab/github_import/importer/repository_importer.rb b/lib/gitlab/github_import/importer/repository_importer.rb index 6d48c6a15b4..6aad7955415 100644 --- a/lib/gitlab/github_import/importer/repository_importer.rb +++ b/lib/gitlab/github_import/importer/repository_importer.rb @@ -54,6 +54,11 @@ module Gitlab project.repository.fetch_as_mirror(project.import_url, refmap: refmap, forced: true, remote_name: 'github') 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 rescue Gitlab::Git::Repository::NoRepository, Gitlab::Shell::Error => e fail_import("Failed to import the repository: #{e.message}") diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb index 41810a8ec03..705df1f4fe7 100644 --- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb @@ -197,6 +197,11 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .to receive(:fetch_as_mirror) .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) end -- cgit v1.2.1