Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b121ffc5
Commit
b121ffc5
authored
May 29, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload queries for ListService and use SQL to filter authorized issues
parent
54b18062
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
app/services/issue_links/list_service.rb
app/services/issue_links/list_service.rb
+6
-4
spec/services/issue_links/list_service_spec.rb
spec/services/issue_links/list_service_spec.rb
+1
-1
No files found.
app/services/issue_links/list_service.rb
View file @
b121ffc5
...
@@ -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
)
...
...
spec/services/issue_links/list_service_spec.rb
View file @
b121ffc5
...
@@ -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
(
4
2
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
4
6
)
end
end
it
'returns related issues JSON'
do
it
'returns related issues JSON'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment