Commit d10b34a685509eebbe52391ffce861cde45cc0ca
1 parent
87c397f5
Exists in
spb-stable
and in
2 other branches
Save repository size to projects table
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
6 changed files
with
34 additions
and
2 deletions
Show diff stats
app/helpers/projects_helper.rb
| ... | ... | @@ -163,7 +163,7 @@ module ProjectsHelper |
| 163 | 163 | end |
| 164 | 164 | |
| 165 | 165 | def repository_size(project = nil) |
| 166 | - "#{(project || @project).repository.size} MB" | |
| 166 | + "#{(project || @project).repository_size} MB" | |
| 167 | 167 | rescue |
| 168 | 168 | # In order to prevent 500 error |
| 169 | 169 | # when application cannot allocate memory | ... | ... |
app/models/project.rb
app/services/git_push_service.rb
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +class MigrateRepoSize < ActiveRecord::Migration | |
| 2 | + def up | |
| 3 | + Project.reset_column_information | |
| 4 | + Project.find_each(batch_size: 500) do |project| | |
| 5 | + begin | |
| 6 | + if project.empty_repo? | |
| 7 | + print '-' | |
| 8 | + else | |
| 9 | + project.update_repository_size | |
| 10 | + print '.' | |
| 11 | + end | |
| 12 | + rescue | |
| 13 | + print 'F' | |
| 14 | + end | |
| 15 | + end | |
| 16 | + puts 'Done' | |
| 17 | + end | |
| 18 | + | |
| 19 | + def down | |
| 20 | + end | |
| 21 | +end | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended that you check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(version: 20140428105831) do | |
| 14 | +ActiveRecord::Schema.define(version: 20140502125220) do | |
| 15 | 15 | |
| 16 | 16 | # These are extensions that must be enabled in order to support this database |
| 17 | 17 | enable_extension "plpgsql" |
| ... | ... | @@ -222,6 +222,7 @@ ActiveRecord::Schema.define(version: 20140428105831) do |
| 222 | 222 | t.integer "visibility_level", default: 0, null: false |
| 223 | 223 | t.boolean "archived", default: false, null: false |
| 224 | 224 | t.string "import_status" |
| 225 | + t.float "repository_size", default: 0.0 | |
| 225 | 226 | end |
| 226 | 227 | |
| 227 | 228 | add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree | ... | ... |