diff options
author | Stan Hu <stanhu@gmail.com> | 2016-04-18 07:42:26 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-04-18 11:05:16 -0700 |
commit | f30053ba608ccc7a9edc8ca720ba09ab15a8f1f5 (patch) | |
tree | 4eaa2fef6974a4dee644ef733a99595082979200 /db | |
parent | 70e6fa31064984c691e283eddf6712bc031e0842 (diff) | |
download | gitlab-ce-f30053ba608ccc7a9edc8ca720ba09ab15a8f1f5.tar.gz |
Use raw SQL commands for 20140502125220 MigrateRepoSize
Partial fix for #15210
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20140502125220_migrate_repo_size.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/db/migrate/20140502125220_migrate_repo_size.rb b/db/migrate/20140502125220_migrate_repo_size.rb index eed6d366814..efdf53112fd 100644 --- a/db/migrate/20140502125220_migrate_repo_size.rb +++ b/db/migrate/20140502125220_migrate_repo_size.rb @@ -1,19 +1,26 @@ class MigrateRepoSize < ActiveRecord::Migration def up - Project.reset_column_information - Project.find_each(batch_size: 500) do |project| + project_data = execute('SELECT projects.id, namespaces.path AS namespace_path, projects.path AS project_path FROM projects LEFT JOIN namespaces ON projects.namespace_id = namespaces.id') + + project_data.each do |project| + id = project['id'] + namespace_path = project['namespace_path'] || '' + path = File.join(Gitlab.config.gitlab_shell.repos_path, namespace_path, project['project_path'] + '.git') + begin - if project.empty_repo? + repo = Gitlab::Git::Repository.new(path) + if repo.empty? print '-' else - project.update_repository_size + size = repo.size print '.' + execute("UPDATE projects SET repository_size = #{size} WHERE id = #{id}") end - rescue - print 'F' + rescue => e + puts "\nFailed to update project #{id}: #{e}" end end - puts 'Done' + puts "\nDone" end def down |