Commit 8a1deea58673b66cd99e06877914ef32b15f3944
1 parent
6d5c9698
Exists in
master
and in
4 other branches
Fixes timeout when adding an SSH key
Users with many projects (>100) will hit the 20 second timeout when updating the gitolite config. This fix batches those changes into a signle update to the file, causing an order of magnitude speed increase which finishes well below the 20 second timeout. Fixes gitlabhq/gitlabhq#220
Showing
2 changed files
with
30 additions
and
8 deletions
Show diff stats
app/models/key.rb
| ... | ... | @@ -21,20 +21,14 @@ class Key < ActiveRecord::Base |
| 21 | 21 | def update_repository |
| 22 | 22 | Gitlabhq::GitHost.system.new.configure do |c| |
| 23 | 23 | c.update_keys(identifier, key) |
| 24 | - | |
| 25 | - projects.each do |project| | |
| 26 | - c.update_project(project.path, project) | |
| 27 | - end | |
| 24 | + c.update_projects(projects) | |
| 28 | 25 | end |
| 29 | 26 | end |
| 30 | 27 | |
| 31 | 28 | def repository_delete_key |
| 32 | 29 | Gitlabhq::GitHost.system.new.configure do |c| |
| 33 | 30 | c.delete_key(identifier) |
| 34 | - | |
| 35 | - projects.each do |project| | |
| 36 | - c.update_project(project.path, project) | |
| 37 | - end | |
| 31 | + c.update_projects(projects) | |
| 38 | 32 | end |
| 39 | 33 | end |
| 40 | 34 | ... | ... |
lib/gitlabhq/gitolite.rb
| ... | ... | @@ -81,5 +81,33 @@ module Gitlabhq |
| 81 | 81 | |
| 82 | 82 | ga_repo.save |
| 83 | 83 | end |
| 84 | + | |
| 85 | + # Updates many projects and uses project.path as the repo path | |
| 86 | + # An order of magnitude faster than update_project | |
| 87 | + def update_projects(projects) | |
| 88 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
| 89 | + conf = ga_repo.config | |
| 90 | + | |
| 91 | + projects.each do |project| | |
| 92 | + repo_name = project.path | |
| 93 | + | |
| 94 | + repo = if conf.has_repo?(repo_name) | |
| 95 | + conf.get_repo(repo_name) | |
| 96 | + else | |
| 97 | + ::Gitolite::Config::Repo.new(repo_name) | |
| 98 | + end | |
| 99 | + | |
| 100 | + name_readers = project.repository_readers | |
| 101 | + name_writers = project.repository_writers | |
| 102 | + | |
| 103 | + repo.clean_permissions | |
| 104 | + repo.add_permission("R", "", name_readers) unless name_readers.blank? | |
| 105 | + repo.add_permission("RW+", "", name_writers) unless name_writers.blank? | |
| 106 | + conf.add_repo(repo, true) | |
| 107 | + end | |
| 108 | + | |
| 109 | + ga_repo.save | |
| 110 | + end | |
| 111 | + | |
| 84 | 112 | end |
| 85 | 113 | end | ... | ... |