summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-10-07 15:24:09 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-10-10 12:27:08 +0200
commit237c8f66e6608420629503280aaea555ee980022 (patch)
treefa50e780b93cd9d812383625d987efd45a63f98b /spec/finders
parent434d98b22a6381447a9c59cec16fc324ade198df (diff)
downloadgitlab-ce-237c8f66e6608420629503280aaea555ee980022.tar.gz
Precalculate trending projectsprecalculate-trending-projects
This commit introduces a Sidekiq worker that precalculates the list of trending projects on a daily basis. The resulting set is stored in a database table that is then queried by Project.trending. This setup means that Unicorn workers no longer _may_ have to calculate the list of trending projects. Furthermore it supports filtering without any complex caching mechanisms. The data in the "trending_projects" table is inserted in the same order as the project ranking. This means that getting the projects in the correct order is simply a matter of: SELECT projects.* FROM projects INNER JOIN trending_projects ON trending_projects.project_id = projects.id ORDER BY trending_projects.id ASC; Such a query will only take a few milliseconds at most (as measured on GitLab.com), opposed to a few seconds for the query used for calculating the project ranks. The migration in this commit does not require downtime and takes care of populating an initial list of trending projects.
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/trending_projects_finder_spec.rb48
1 files changed, 0 insertions, 48 deletions
diff --git a/spec/finders/trending_projects_finder_spec.rb b/spec/finders/trending_projects_finder_spec.rb
deleted file mode 100644
index cfe15b9defa..00000000000
--- a/spec/finders/trending_projects_finder_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require 'spec_helper'
-
-describe TrendingProjectsFinder do
- 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
-
- 2.times do
- create(:note_on_commit, project: public_project2, created_at: 5.weeks.ago)
- end
-
- create(:note_on_commit, project: private_project)
- create(:note_on_commit, project: internal_project)
- end
-
- describe '#execute', caching: true do
- context 'without an explicit time range' do
- it 'returns public trending projects' do
- projects = described_class.new.execute
-
- expect(projects).to eq([public_project1])
- end
- end
-
- context 'with an explicit time range' do
- it 'returns public trending projects' do
- projects = described_class.new.execute(2)
-
- expect(projects).to eq([public_project1, public_project2])
- end
- end
-
- it 'caches the list of projects' do
- projects = described_class.new
-
- expect(Project).to receive(:trending).once
-
- 2.times { projects.execute }
- end
- end
-end