diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/note.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 47 |
3 files changed, 23 insertions, 30 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 62567f471dc..2362e50276e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -31,7 +31,7 @@ class Note < ActiveRecord::Base participant :author, :mentioned_users belongs_to :project - belongs_to :noteable, polymorphic: true, touch: true + belongs_to :noteable, polymorphic: true belongs_to :author, class_name: "User" delegate :name, to: :project, prefix: true 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 6262b5c4c92..277a9178592 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 @@ -130,28 +118,29 @@ class Repository cache.fetch(:size) { raw_repository.size } end + def cache_keys + %i(size branch_names tag_names commit_count + readme version contribution_guide changelog license) + end + + def build_cache + cache_keys.each do |key| + unless cache.exist?(key) + send(key) + end + end + end + def expire_cache - %i(size branch_names tag_names commit_count graph_log - readme version contribution_guide changelog license).each do |key| + cache_keys.each do |key| cache.expire(key) end end - def graph_log - cache.fetch(:graph_log) do - commits = raw_repository.log(limit: 6000, skip_merges: true, - ref: root_ref) - - commits.map do |rugged_commit| - commit = Gitlab::Git::Commit.new(rugged_commit) - - { - author_name: commit.author_name, - author_email: commit.author_email, - additions: commit.stats.additions, - deletions: commit.stats.deletions, - } - end + def rebuild_cache + cache_keys.each do |key| + cache.expire(key) + send(key) end end |