summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-07-17 15:22:56 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-07-17 15:22:56 +0200
commitf0116f13354fa1e57e3ba8013ea67d3b0e193375 (patch)
treeeb3768402c49b239d1898350399f0edd82da81e8
parent67ca5a53f6df0c3d0f2598c777491c0548d76e50 (diff)
downloadgitlab-ce-advanced-cache.tar.gz
Store commit count in project tableadvanced-cache
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/helpers/projects_helper.rb14
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/repository.rb12
-rw-r--r--app/services/git_push_service.rb1
-rw-r--r--app/views/explore/projects/_project.html.haml2
-rw-r--r--app/views/projects/show.html.haml2
-rw-r--r--app/workers/project_cache_worker.rb5
-rw-r--r--app/workers/repository_import_worker.rb2
-rw-r--r--db/migrate/20150717130904_add_commits_count_to_project.rb5
-rw-r--r--db/schema.rb3
-rw-r--r--lib/repository_cache.rb6
11 files changed, 37 insertions, 19 deletions
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 78f24dbd7ef..f61baf00525 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -276,4 +276,18 @@ module ProjectsHelper
def readme_cache_key
[@project.id, @project.commit.sha, "readme"].join('-')
end
+
+ def round_commit_count(project)
+ count = project.commit_count
+
+ if count > 10000
+ '10000+'
+ elsif count > 5000
+ '5000+'
+ elsif count > 1000
+ '1000+'
+ else
+ count
+ end
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index b161cbe86b9..ff372ea9aa5 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -683,6 +683,10 @@ class Project < ActiveRecord::Base
update_attribute(:repository_size, repository.size)
end
+ def update_commit_count
+ update_attribute(:commit_count, repository.commit_count)
+ end
+
def forks_count
ForkedProjectLink.where(forked_from_project_id: self.id).count
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index bca14aa1a33..2985619fd2e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -94,18 +94,6 @@ class Repository
gitlab_shell.rm_tag(path_with_namespace, tag_name)
end
- def round_commit_count
- if commit_count > 10000
- '10000+'
- elsif commit_count > 5000
- '5000+'
- elsif commit_count > 1000
- '1000+'
- else
- commit_count
- end
- end
-
def branch_names
cache.fetch(:branch_names) { raw_repository.branch_names }
end
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index c36113329ea..3511392d1d8 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -21,7 +21,6 @@ class GitPushService
project.ensure_satellite_exists
project.repository.expire_cache
- project.update_repository_size
if push_remove_branch?(ref, newrev)
@push_commits = []
diff --git a/app/views/explore/projects/_project.html.haml b/app/views/explore/projects/_project.html.haml
index d65fb529373..d769c91545d 100644
--- a/app/views/explore/projects/_project.html.haml
+++ b/app/views/explore/projects/_project.html.haml
@@ -14,7 +14,7 @@
.repo-info
- unless project.empty_repo?
- = link_to pluralize(project.repository.round_commit_count, 'commit'), namespace_project_commits_path(project.namespace, project, project.default_branch)
+ = link_to pluralize(round_commit_count(project), 'commit'), namespace_project_commits_path(project.namespace, project, project.default_branch)
&middot;
= link_to pluralize(project.repository.branch_names.count, 'branch'), namespace_project_branches_path(project.namespace, project)
&middot;
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index 98d9053eb1d..b90cadfb1e2 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -13,7 +13,7 @@
%ul.nav.nav-pills
%li
= link_to namespace_project_commits_path(@project.namespace, @project, @ref || @repository.root_ref) do
- = pluralize(number_with_delimiter(@repository.commit_count), 'commit')
+ = pluralize(number_with_delimiter(@project.commit_count), 'commit')
%li
= link_to namespace_project_branches_path(@project.namespace, @project) do
= pluralize(number_with_delimiter(@repository.branch_names.count), 'branch')
diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb
index 4c14565dce5..61416d634bd 100644
--- a/app/workers/project_cache_worker.rb
+++ b/app/workers/project_cache_worker.rb
@@ -4,6 +4,9 @@ class ProjectCacheWorker
sidekiq_options queue: :default
def perform(project_id)
- Project.find(project_id).repository.build_cache
+ project = Project.find(project_id)
+ project.update_repository_size
+ project.update_commit_count
+ project.repository.build_cache
end
end
diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb
index e6a50afedb1..94832872d13 100644
--- a/app/workers/repository_import_worker.rb
+++ b/app/workers/repository_import_worker.rb
@@ -28,7 +28,7 @@ class RepositoryImportWorker
project.import_finish
project.save
project.satellite.create unless project.satellite.exists?
- project.update_repository_size
+ ProjectCacheWorker.perform_async(project.id)
Gitlab::BitbucketImport::KeyDeleter.new(project).execute if project.import_type == 'bitbucket'
end
end
diff --git a/db/migrate/20150717130904_add_commits_count_to_project.rb b/db/migrate/20150717130904_add_commits_count_to_project.rb
new file mode 100644
index 00000000000..9b46daa5933
--- /dev/null
+++ b/db/migrate/20150717130904_add_commits_count_to_project.rb
@@ -0,0 +1,5 @@
+class AddCommitsCountToProject < ActiveRecord::Migration
+ def change
+ add_column :projects, :commit_count, :integer, default: 0
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d6c34a77ee6..a63c2d05821 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150713160110) do
+ActiveRecord::Schema.define(version: 20150717130904) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -374,6 +374,7 @@ ActiveRecord::Schema.define(version: 20150713160110) do
t.integer "star_count", default: 0, null: false
t.string "import_type"
t.string "import_source"
+ t.integer "commit_count", default: 0
end
add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree
diff --git a/lib/repository_cache.rb b/lib/repository_cache.rb
index 639687067ec..8ddc3511293 100644
--- a/lib/repository_cache.rb
+++ b/lib/repository_cache.rb
@@ -20,6 +20,10 @@ class RepositoryCache
end
def exist?(key)
- backend.exist?(key)
+ backend.exist?(cache_key(key))
+ end
+
+ def read(key)
+ backend.read(cache_key(key))
end
end