diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-17 15:22:56 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-17 15:22:56 +0200 |
commit | f0116f13354fa1e57e3ba8013ea67d3b0e193375 (patch) | |
tree | eb3768402c49b239d1898350399f0edd82da81e8 /app | |
parent | 67ca5a53f6df0c3d0f2598c777491c0548d76e50 (diff) | |
download | gitlab-ce-f0116f13354fa1e57e3ba8013ea67d3b0e193375.tar.gz |
Store commit count in project tableadvanced-cache
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/projects_helper.rb | 14 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 12 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 1 | ||||
-rw-r--r-- | app/views/explore/projects/_project.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/show.html.haml | 2 | ||||
-rw-r--r-- | app/workers/project_cache_worker.rb | 5 | ||||
-rw-r--r-- | app/workers/repository_import_worker.rb | 2 |
8 files changed, 25 insertions, 17 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) · = link_to pluralize(project.repository.branch_names.count, 'branch'), namespace_project_branches_path(project.namespace, project) · 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 |