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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
14917675
Commit
14917675
authored
Jun 10, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Issue.visible_to_user in Notes.search to avoid query duplication
parent
b56c4567
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
30 deletions
+14
-30
app/models/issue.rb
app/models/issue.rb
+1
-1
app/models/note.rb
app/models/note.rb
+3
-16
app/models/user.rb
app/models/user.rb
+10
-13
No files found.
app/models/issue.rb
View file @
14917675
...
...
@@ -51,7 +51,7 @@ class Issue < ActiveRecord::Base
end
def
self
.
visible_to_user
(
user
)
return
where
(
confidential:
false
)
if
user
.
blank?
return
where
(
'issues.confidential IS NULL OR issues.confidential IS FALSE'
)
if
user
.
blank?
return
all
if
user
.
admin?
where
(
'
...
...
app/models/note.rb
View file @
14917675
...
...
@@ -88,22 +88,9 @@ class Note < ActiveRecord::Base
table
=
arel_table
pattern
=
"%
#{
query
}
%"
found_notes
=
joins
(
'LEFT JOIN issues ON issues.id = noteable_id'
).
where
(
table
[
:note
].
matches
(
pattern
))
if
as_user
found_notes
.
where
(
'
issues.confidential IS NULL
OR issues.confidential IS FALSE
OR (issues.confidential IS TRUE
AND (issues.author_id = :user_id
OR issues.assignee_id = :user_id
OR issues.project_id IN(:project_ids)))'
,
user_id:
as_user
.
id
,
project_ids:
as_user
.
authorized_projects
(
Gitlab
::
Access
::
REPORTER
).
select
(
:id
))
else
found_notes
.
where
(
'issues.confidential IS NULL OR issues.confidential IS FALSE'
)
end
Note
.
joins
(
'LEFT JOIN issues ON issues.id = noteable_id'
).
where
(
table
[
:note
].
matches
(
pattern
)).
merge
(
Issue
.
visible_to_user
(
as_user
))
end
end
...
...
app/models/user.rb
View file @
14917675
...
...
@@ -825,19 +825,16 @@ class User < ActiveRecord::Base
private
def
projects_union
(
min_access_level
=
nil
)
relations
=
if
min_access_level
scope
=
{
access_level:
Gitlab
::
Access
.
values
.
select
{
|
access
|
access
>=
min_access_level
}
}
[
personal_projects
.
select
(
:id
),
groups_projects
.
where
(
members:
scope
).
select
(
:id
),
projects
.
where
(
members:
scope
).
select
(
:id
),
groups
.
joins
(
:shared_projects
).
where
(
members:
scope
).
select
(
:project_id
)]
else
[
personal_projects
.
select
(
:id
),
groups_projects
.
select
(
:id
),
projects
.
select
(
:id
),
groups
.
joins
(
:shared_projects
).
select
(
:project_id
)]
end
relations
=
[
personal_projects
.
select
(
:id
),
groups_projects
.
select
(
:id
),
projects
.
select
(
:id
),
groups
.
joins
(
:shared_projects
).
select
(
:project_id
)]
if
min_access_level
scope
=
{
access_level:
Gitlab
::
Access
.
values
.
select
{
|
access
|
access
>=
min_access_level
}
}
relations
=
[
relations
.
shift
]
+
relations
.
map
{
|
relation
|
relation
.
where
(
members:
scope
)
}
end
Gitlab
::
SQL
::
Union
.
new
(
relations
)
end
...
...
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