summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-14 14:56:13 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-14 14:56:13 +0000
commitc0c314c6bfe3640d724955d7d4eae7b9f7e1d2b1 (patch)
tree3923e3cb650f4e5873c50326a21941e789ca69af /app/models/project.rb
parente72b9ffe98996e8fb7a104ab4b1ce8671b1186c8 (diff)
parent9995f0806b29934cf498607f59d2c5ec358a0d5a (diff)
downloadgitlab-ce-c0c314c6bfe3640d724955d7d4eae7b9f7e1d2b1.tar.gz
Merge branch 'forked-repo-creation-async' into 'master'
Import forked repositories asynchronously to prevent large repositories from timing out Preserve synchronous mode of adding a repository since some tasks (e.g. restore/check) require the former. One side bug fix is that the `ProjectCacheWorker` is also run, updating the repository size and commit numbers properly. Previously all the values were set to 0 when a project were forked. * Closes #2388 * Closes #2400 See merge request !1231
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 072d7d73f41..49525eb9227 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -144,7 +144,7 @@ class Project < ActiveRecord::Base
validates_uniqueness_of :path, scope: :namespace_id
validates :import_url,
format: { with: /\A#{URI.regexp(%w(ssh git http https))}\z/, message: 'should be a valid url' },
- if: :import?
+ if: :external_import?
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
validate :avatar_type,
@@ -275,7 +275,13 @@ class Project < ActiveRecord::Base
end
def add_import_job
- RepositoryImportWorker.perform_in(2.seconds, id)
+ if forked?
+ unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path)
+ import_fail
+ end
+ else
+ RepositoryImportWorker.perform_in(2.seconds, id)
+ end
end
def clear_import_data
@@ -283,6 +289,10 @@ class Project < ActiveRecord::Base
end
def import?
+ external_import? || forked?
+ end
+
+ def external_import?
import_url.present?
end
@@ -702,14 +712,8 @@ class Project < ActiveRecord::Base
end
def create_repository
- if forked?
- if gitlab_shell.fork_repository(forked_from_project.path_with_namespace, self.namespace.path)
- true
- else
- errors.add(:base, 'Failed to fork repository via gitlab-shell')
- false
- end
- else
+ # Forked import is handled asynchronously
+ unless forked?
if gitlab_shell.add_repository(path_with_namespace)
true
else