Commit 9dfc4fe6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'repo-size-in-db' into 'master'

Save repository size to projects table

This will allow us to get largest repos by simple sql query.

Also it increase loading of `admin/projects` page a lot because right now it calculate 20x project sizes per page
parents 3bec6e89 d10b34a6
...@@ -163,7 +163,7 @@ module ProjectsHelper ...@@ -163,7 +163,7 @@ module ProjectsHelper
end end
def repository_size(project = nil) def repository_size(project = nil)
"#{(project || @project).repository.size} MB" "#{(project || @project).repository_size} MB"
rescue rescue
# In order to prevent 500 error # In order to prevent 500 error
# when application cannot allocate memory # when application cannot allocate memory
......
...@@ -562,4 +562,8 @@ class Project < ActiveRecord::Base ...@@ -562,4 +562,8 @@ class Project < ActiveRecord::Base
def forked_from?(project) def forked_from?(project)
forked? && project == forked_from_project forked? && project == forked_from_project
end end
def update_repository_size
update_attribute(:repository_size, repository.size)
end
end end
...@@ -25,6 +25,7 @@ class GitPushService ...@@ -25,6 +25,7 @@ class GitPushService
project.ensure_satellite_exists project.ensure_satellite_exists
project.repository.expire_cache project.repository.expire_cache
project.update_repository_size
if push_to_existing_branch?(ref, oldrev) if push_to_existing_branch?(ref, oldrev)
project.update_merge_requests(oldrev, newrev, ref, @user) 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 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -222,6 +222,7 @@ ActiveRecord::Schema.define(version: 20140428105831) do ...@@ -222,6 +222,7 @@ ActiveRecord::Schema.define(version: 20140428105831) do
t.integer "visibility_level", default: 0, null: false t.integer "visibility_level", default: 0, null: false
t.boolean "archived", default: false, null: false t.boolean "archived", default: false, null: false
t.string "import_status" t.string "import_status"
t.float "repository_size", default: 0.0
end end
add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree 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