From 8b54b7233ef58a2a39da9777dbeab59b4024cc75 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Jan 2013 17:39:02 +0200 Subject: [PATCH] Async perform for add/remove team members --- app/models/protected_branch.rb | 2 +- app/models/users_project.rb | 12 ++++++++++-- lib/gitlab/backend/gitolite.rb | 26 +++++++++++++++++++------- spec/lib/gitolite_spec.rb | 2 +- spec/support/stubbed_repository.rb | 4 ++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index 3308caf3..2e7010ea 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -22,7 +22,7 @@ class ProtectedBranch < ActiveRecord::Base after_destroy :update_repository def update_repository - gitolite.update_repository(project) + project.update_repository end def commit diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 32066004..183878cb 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -82,9 +82,13 @@ class UsersProject < ActiveRecord::Base users_project.save end end - Gitlab::Gitolite.new.update_repositories(Project.where(id: project_ids)) end + GitoliteWorker.perform_async( + :update_repositories, + project_ids + ) + true rescue false @@ -97,9 +101,13 @@ class UsersProject < ActiveRecord::Base users_project.skip_git = true users_project.destroy end - Gitlab::Gitolite.new.update_repositories(Project.where(id: project_ids)) end + GitoliteWorker.perform_async( + :update_repositories, + project_ids + ) + true rescue false diff --git a/lib/gitlab/backend/gitolite.rb b/lib/gitlab/backend/gitolite.rb index d026b76f..1bcf1264 100644 --- a/lib/gitlab/backend/gitolite.rb +++ b/lib/gitlab/backend/gitolite.rb @@ -22,7 +22,12 @@ module Gitlab end end - def update_repository project_id + # Update project config in gitolite by project id + # + # Ex. + # update_repository(23) + # + def update_repository(project_id) project = Project.find(project_id) config.update_project!(project) end @@ -45,6 +50,19 @@ module Gitlab config.destroy_project!(name) end + # Update projects configs in gitolite by project ids + # + # Ex. + # update_repositories([1, 4, 6]) + # + def update_repositories(project_ids) + projects = Project.where(id: project_ids) + + config.apply do |config| + config.update_projects(projects) + end + end + def url_to_repo path Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git" end @@ -53,12 +71,6 @@ module Gitlab config.admin_all_repo! end - def update_repositories projects - config.apply do |config| - config.update_projects(projects) - end - end - alias_method :create_repository, :update_repository end end diff --git a/spec/lib/gitolite_spec.rb b/spec/lib/gitolite_spec.rb index 8075b99e..df6dc368 100644 --- a/spec/lib/gitolite_spec.rb +++ b/spec/lib/gitolite_spec.rb @@ -20,6 +20,6 @@ describe Gitlab::Gitolite do it "should call config update" do gitolite_config.should_receive(:update_project!) - gitolite.update_repository project + gitolite.update_repository(project.id) end end diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb index e6e194d7..e092f8a4 100644 --- a/spec/support/stubbed_repository.rb +++ b/spec/support/stubbed_repository.rb @@ -21,6 +21,10 @@ class Project true end + def destroy + true + end + def create true end