Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-10-04 15:09:54 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2016-10-05 17:39:03 +0300
commit154253cab55491d54dfe264fa946acb9c399398a (patch)
tree968997cab3177e34d89fd4c34473cf83bf8682a8 /spec/finders
parent706737a004b67303f15ccbd1f8630b0d80f481e9 (diff)
Refactor TrendingProjectsFinder to support caching
== Public Projects This finder class now _only_ returns public projects. Previously this finder would also return private and internal projects. Including these projects makes caching data much harder and less efficient. Meanwhile including this data isn't very useful as very few users would be interested in seeing projects they have access to as trending. That is, the feature is more useful when you want to see what _other_ popular projects there are. == Caching The data returned by TrendingProjectsFinder is now cached for a day based on the number of months the data should be restricted to. The cache is not flushed explicitly, instead it's rebuilt whenever it expires. == Timings To measure the impact I changed the finder code to use the last 24 months instead of the last month. I then executed and measured 10 requests to the explore page. On the current "master" branch (commit 88fa5916ffa0aea491cd339272ed7437c3f52dc7) this would take an average of 2.43 seconds. Using the changes of this commit this was reduced to around 1.7 seconds. Fixes gitlab-org/gitlab-ce#22164
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/trending_projects_finder_spec.rb53
1 files changed, 31 insertions, 22 deletions
diff --git a/spec/finders/trending_projects_finder_spec.rb b/spec/finders/trending_projects_finder_spec.rb
index a49cbfd5160..cfe15b9defa 100644
--- a/spec/finders/trending_projects_finder_spec.rb
+++ b/spec/finders/trending_projects_finder_spec.rb
@@ -1,39 +1,48 @@
require 'spec_helper'
describe TrendingProjectsFinder do
- let(:user) { build(:user) }
+ let(:user) { create(:user) }
+ let(:public_project1) { create(:empty_project, :public) }
+ let(:public_project2) { create(:empty_project, :public) }
+ let(:private_project) { create(:empty_project, :private) }
+ let(:internal_project) { create(:empty_project, :internal) }
+
+ before do
+ 3.times do
+ create(:note_on_commit, project: public_project1)
+ end
- describe '#execute' do
- describe 'without an explicit start date' do
- subject { described_class.new }
+ 2.times do
+ create(:note_on_commit, project: public_project2, created_at: 5.weeks.ago)
+ end
- it 'returns the trending projects' do
- relation = double(:ar_relation)
+ create(:note_on_commit, project: private_project)
+ create(:note_on_commit, project: internal_project)
+ end
- allow(subject).to receive(:projects_for)
- .with(user)
- .and_return(relation)
+ describe '#execute', caching: true do
+ context 'without an explicit time range' do
+ it 'returns public trending projects' do
+ projects = described_class.new.execute
- allow(relation).to receive(:trending)
- .with(an_instance_of(ActiveSupport::TimeWithZone))
+ expect(projects).to eq([public_project1])
end
end
- describe 'with an explicit start date' do
- let(:date) { 2.months.ago }
+ context 'with an explicit time range' do
+ it 'returns public trending projects' do
+ projects = described_class.new.execute(2)
- subject { described_class.new }
+ expect(projects).to eq([public_project1, public_project2])
+ end
+ end
- it 'returns the trending projects' do
- relation = double(:ar_relation)
+ it 'caches the list of projects' do
+ projects = described_class.new
- allow(subject).to receive(:projects_for)
- .with(user)
- .and_return(relation)
+ expect(Project).to receive(:trending).once
- allow(relation).to receive(:trending)
- .with(date)
- end
+ 2.times { projects.execute }
end
end
end