Unverified Commit d10b34a6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Save repository size to projects table


Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a78514448f60
......@@ -163,7 +163,7 @@ def git_user_email
end
def repository_size(project = nil)
"#{(project || @project).repository.size} MB"
"#{(project || @project).repository_size} MB"
rescue
# In order to prevent 500 error
# when application cannot allocate memory
......
......@@ -562,4 +562,8 @@ def change_head(branch)
def forked_from?(project)
forked? && project == forked_from_project
end
def update_repository_size
update_attribute(:repository_size, repository.size)
end
end
......@@ -25,6 +25,7 @@ def execute(project, user, oldrev, newrev, ref)
project.ensure_satellite_exists
project.repository.expire_cache
project.update_repository_size
if push_to_existing_branch?(ref, oldrev)
project.update_merge_requests(oldrev, newrev, ref, @user)
......
class AddRepoSizeToDb < ActiveRecord::Migration
def change
add_column :projects, :repository_size, :float, default: 0
end
end
class MigrateRepoSize < ActiveRecord::Migration
def up
Project.reset_column_information
Project.find_each(batch_size: 500) do |project|
begin
if project.empty_repo?
print '-'
else
project.update_repository_size
print '.'
end
rescue
print 'F'
end
end
puts 'Done'
end
def down
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140428105831) do
ActiveRecord::Schema.define(version: 20140502125220) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -222,6 +222,7 @@
t.integer "visibility_level", default: 0, null: false
t.boolean "archived", default: false, null: false
t.string "import_status"
t.float "repository_size", default: 0.0
end
add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment