mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-20 10:06:04 +10:00
Save repository size to projects table
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
@@ -163,7 +163,7 @@ module ProjectsHelper
|
||||
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 @@ class Project < ActiveRecord::Base
|
||||
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 @@ class GitPushService
|
||||
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddRepoSizeToDb < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :projects, :repository_size, :float, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
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
|
||||
+2
-1
@@ -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 @@ ActiveRecord::Schema.define(version: 20140428105831) do
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user