summaryrefslogtreecommitdiff
path: root/spec/models/project_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-08-14 15:22:09 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-08-14 18:00:28 +0200
commitaef9f1eb9405e9bab92b15f5c99bf06eaf28a5d6 (patch)
tree01ebae601e9df77c1b2887e0783b73b30f833b2b /spec/models/project_spec.rb
parent21a6898b10ed75f6260e72467b9e1f839d48456c (diff)
downloadgitlab-ce-aef9f1eb9405e9bab92b15f5c99bf06eaf28a5d6.tar.gz
Cache the number of forks of a projectforks-count-cache
The number of forks of a project doesn't change very frequently and running a COUNT(*) every time this information is requested can be quite expensive. We also end up running such a COUNT(*) query at least twice on the homepage of a project. By caching this data and refreshing it when necessary we can reduce project homepage loading times by around 60 milliseconds (based on the timings of https://gitlab.com/gitlab-org/gitlab-ce).
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r--spec/models/project_spec.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index d9ab44dc49f..eba71ba2f72 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2310,4 +2310,14 @@ describe Project do
end
end
end
+
+ describe '#forks_count' do
+ it 'returns the number of forks' do
+ project = build(:project)
+
+ allow(project.forks).to receive(:count).and_return(1)
+
+ expect(project.forks_count).to eq(1)
+ end
+ end
end