Commit b121ffc5 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Preload queries for ListService and use SQL to filter authorized issues

parent 54b18062
...@@ -26,14 +26,16 @@ module IssueLinks ...@@ -26,14 +26,16 @@ module IssueLinks
def issues def issues
return @issues if defined?(@issues) return @issues if defined?(@issues)
authorized_issues = IssuesFinder.new(@current_user, project_id: @project.id).execute
referenced_issues = @issue.referenced_issues.select('issues.*', 'issue_links.id AS issue_links_id') referenced_issues = @issue.referenced_issues.select('issues.*', 'issue_links.id AS issue_links_id')
referred_by_issues = @issue.referred_by_issues.select('issues.*', 'issue_links.id AS issue_links_id') referred_by_issues = @issue.referred_by_issues.select('issues.*', 'issue_links.id AS issue_links_id')
union = Gitlab::SQL::Union.new([referenced_issues, referred_by_issues])
sql = "#{union.to_sql} ORDER BY issue_links_id" union = Gitlab::SQL::Union.new([referenced_issues, referred_by_issues])
@issues = Issue.find_by_sql(sql) @issues = Issue.from("(#{union.to_sql}) #{Issue.table_name}")
@issues = Ability.issues_readable_by_user(@issues, @current_user) .where(id: authorized_issues.select(:id))
.preload(project: :namespace)
.reorder('issue_links_id')
end end
def destroy_relation_path(issue) def destroy_relation_path(issue)
......
...@@ -38,7 +38,7 @@ describe IssueLinks::ListService, service: true do ...@@ -38,7 +38,7 @@ describe IssueLinks::ListService, service: true do
it 'verifies number of queries' do it 'verifies number of queries' do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(42) expect(recorded.count).to be_within(1).of(46)
end end
it 'returns related issues JSON' do it 'returns related issues JSON' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment