summaryrefslogtreecommitdiff
path: root/spec/requests/api/v3/projects_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/requests/api/v3/projects_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/requests/api/v3/projects_spec.rb')
-rw-r--r--spec/requests/api/v3/projects_spec.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/requests/api/v3/projects_spec.rb b/spec/requests/api/v3/projects_spec.rb
index fca5b5b5d82..a514166274a 100644
--- a/spec/requests/api/v3/projects_spec.rb
+++ b/spec/requests/api/v3/projects_spec.rb
@@ -1004,6 +1004,14 @@ describe API::V3::Projects do
expect(project_fork_target.forked?).to be_truthy
end
+ it 'refreshes the forks count cachce' do
+ expect(project_fork_source.forks_count).to be_zero
+
+ post v3_api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin)
+
+ expect(project_fork_source.forks_count).to eq(1)
+ end
+
it 'fails if forked_from project which does not exist' do
post v3_api("/projects/#{project_fork_target.id}/fork/9999", admin)
expect(response).to have_http_status(404)