6ec53f5d48
Every project page displays a navigation menu that in turn displays the number of open issues and merge requests. This means that for every project page we run two COUNT(*) queries, each taking up roughly 30 milliseconds on GitLab.com. By caching these numbers and refreshing them whenever necessary we can reduce loading times of all these pages by up to roughly 60 milliseconds. The number of open issues does not include confidential issues. This is a trade-off to keep the code simple and to ensure refreshing the data only needs 2 COUNT(*) queries instead of 3. A downside is that if a project only has 5 confidential issues the counter will be set to 0. Because we now have 3 similar counting service classes the code previously used in Projects::ForksCountService has mostly been moved to Projects::CountService, which in turn is reused by the various service classes. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/36622
14 lines
331 B
Ruby
14 lines
331 B
Ruby
require 'spec_helper'
|
|
|
|
describe Projects::ForksCountService do
|
|
describe '#count' do
|
|
it 'returns the number of forks' do
|
|
project = build(:project, id: 42)
|
|
service = described_class.new(project)
|
|
|
|
allow(service).to receive(:uncached_count).and_return(1)
|
|
|
|
expect(service.count).to eq(1)
|
|
end
|
|
end
|
|
end
|