Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'finding-issues-by-labels-performance' into 'master'
Improve performance of finding issues with/without labels The changes in this MR ultimately lead to finding issues with(out) labels being about 2x faster due to: 1. Newly added indexes on `issues.state` and `projects.visibility_level` 2. Adjusting the query so that finding issues for multiple projects is more efficient See merge request !1787
- Loading branch information
Showing
8 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIssuesStateIndex < ActiveRecord::Migration | ||
def change | ||
add_index :issues, :state | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20151109134916_add_projects_visibility_level_index.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddProjectsVisibilityLevelIndex < ActiveRecord::Migration | ||
def change | ||
add_index :projects, :visibility_level | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'spec_helper' | ||
|
||
describe IssuesFinder, benchmark: true do | ||
describe '#execute' do | ||
let(:user) { create(:user) } | ||
let(:project) { create(:project, :public) } | ||
|
||
let(:label1) { create(:label, project: project, title: 'A') } | ||
let(:label2) { create(:label, project: project, title: 'B') } | ||
|
||
before do | ||
10.times do |n| | ||
issue = create(:issue, author: user, project: project) | ||
|
||
if n > 4 | ||
create(:label_link, label: label1, target: issue) | ||
create(:label_link, label: label2, target: issue) | ||
end | ||
end | ||
end | ||
|
||
describe 'retrieving issues without labels' do | ||
let(:finder) do | ||
IssuesFinder.new(user, scope: 'all', label_name: Label::None.title, | ||
state: 'opened') | ||
end | ||
|
||
benchmark_subject { finder.execute } | ||
|
||
it { is_expected.to iterate_per_second(2000) } | ||
end | ||
|
||
describe 'retrieving issues with labels' do | ||
let(:finder) do | ||
IssuesFinder.new(user, scope: 'all', label_name: label1.title, | ||
state: 'opened') | ||
end | ||
|
||
benchmark_subject { finder.execute } | ||
|
||
it { is_expected.to iterate_per_second(1000) } | ||
end | ||
|
||
describe 'retrieving issues for a single project' do | ||
let(:finder) do | ||
IssuesFinder.new(user, scope: 'all', label_name: Label::None.title, | ||
state: 'opened', project_id: project.id) | ||
end | ||
|
||
benchmark_subject { finder.execute } | ||
|
||
it { is_expected.to iterate_per_second(2000) } | ||
end | ||
end | ||
end |