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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
9127ae5c
Commit
9127ae5c
authored
Oct 14, 2015
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve performance of queries
Credits to Douwe Maan
parent
ac44e384
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
34 deletions
+47
-34
CHANGELOG
CHANGELOG
+1
-0
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+46
-28
db/migrate/20151013133938_add_index_to_milestones.rb
db/migrate/20151013133938_add_index_to_milestones.rb
+0
-6
No files found.
CHANGELOG
View file @
9127ae5c
...
@@ -63,6 +63,7 @@ v 8.1.0 (unreleased)
...
@@ -63,6 +63,7 @@ v 8.1.0 (unreleased)
- Only render 404 page from /public
- Only render 404 page from /public
- Hide passwords from services API (Alex Lossent)
- Hide passwords from services API (Alex Lossent)
- Fix: Images cannot show when projects' path was changed
- Fix: Images cannot show when projects' path was changed
- Optimize query when filtering on issuables (Zeger-Jan van de Weg)
v 8.0.4
v 8.0.4
- Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu)
- Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu)
...
...
app/finders/issuable_finder.rb
View file @
9127ae5c
...
@@ -53,15 +53,36 @@ class IssuableFinder
...
@@ -53,15 +53,36 @@ class IssuableFinder
end
end
end
end
def
project?
params
[
:project_id
].
present?
end
def
project
def
project
return
@project
if
defined?
(
@project
)
return
@project
if
defined?
(
@project
)
@project
=
if
project?
if
params
[
:project_id
].
present?
@project
=
Project
.
find
(
params
[
:project_id
])
Project
.
find
(
params
[
:project_id
])
else
unless
Ability
.
abilities
.
allowed?
(
current_user
,
:read_project
,
@project
)
nil
@project
=
nil
end
end
else
@project
=
nil
end
@project
end
def
projects
return
if
project?
return
@projects
if
defined?
(
@projects
)
if
current_user
&&
params
[
:authorized_only
].
presence
&&
!
current_user_related?
current_user
.
authorized_projects
else
ProjectsFinder
.
new
.
execute
(
current_user
)
end
end
end
def
search
def
search
...
@@ -84,8 +105,10 @@ class IssuableFinder
...
@@ -84,8 +105,10 @@ class IssuableFinder
scope
=
scope
=
if
project
if
project
project
.
milestones
project
.
milestones
elsif
projects
Milestone
.
where
(
project_id:
projects
)
else
else
Milestone
.
all
Milestone
.
none
end
end
scope
.
where
(
title:
params
[
:milestone_title
])
scope
.
where
(
title:
params
[
:milestone_title
])
...
@@ -127,19 +150,7 @@ class IssuableFinder
...
@@ -127,19 +150,7 @@ class IssuableFinder
private
private
def
init_collection
def
init_collection
table_name
=
klass
.
table_name
klass
.
all
if
project
if
Ability
.
abilities
.
allowed?
(
current_user
,
:read_project
,
project
)
project
.
send
(
table_name
)
else
[]
end
elsif
current_user
&&
params
[
:authorized_only
].
presence
&&
!
current_user_related?
klass
.
of_projects
(
current_user
.
authorized_projects
).
references
(
:project
)
else
klass
.
of_projects
(
ProjectsFinder
.
new
.
execute
(
current_user
)).
references
(
:project
)
end
end
end
def
by_scope
(
items
)
def
by_scope
(
items
)
...
@@ -177,7 +188,14 @@ class IssuableFinder
...
@@ -177,7 +188,14 @@ class IssuableFinder
end
end
def
by_project
(
items
)
def
by_project
(
items
)
items
=
items
.
of_projects
(
project
.
id
)
if
project
items
=
if
project
items
.
of_projects
(
project
)
elsif
projects
items
.
of_projects
(
projects
).
references
(
:project
)
else
items
.
none
end
items
items
end
end
...
@@ -223,17 +241,17 @@ class IssuableFinder
...
@@ -223,17 +241,17 @@ class IssuableFinder
def
by_label
(
items
)
def
by_label
(
items
)
if
params
[
:label_name
].
present?
if
params
[
:label_name
].
present?
if
params
[
:label_name
]
==
Label
::
None
.
title
if
params
[
:label_name
]
==
Label
::
None
.
title
item
_ids
=
LabelLink
.
where
(
target_type:
klass
.
name
).
pluck
(
:target_id
)
item
s
=
items
.
joins
(
"LEFT OUTER JOIN label_links ON label_links.target_type = '
#{
klass
.
name
}
' AND label_links.target_id =
#{
klass
.
table_name
}
.id"
).
items
=
items
.
where
(
'id NOT IN (?)'
,
item_ids
)
where
(
label_links:
{
id:
nil
}
)
else
else
label_names
=
params
[
:label_name
].
split
(
","
)
label_names
=
params
[
:label_name
].
split
(
","
)
item_ids
=
LabelLink
.
joins
(
:label
).
items
=
items
.
joins
(
:labels
).
where
(
labels:
{
title:
label_names
})
where
(
'labels.title in (?)'
,
label_names
).
where
(
target_type:
klass
.
name
).
pluck
(
:target_id
)
items
=
items
.
where
(
id:
item_ids
)
if
project
items
=
items
.
where
(
'labels.project_id = :id'
,
id:
project
.
id
)
end
end
end
end
end
...
...
db/migrate/20151013133938_add_index_to_milestones.rb
deleted
100644 → 0
View file @
ac44e384
class
AddIndexToMilestones
<
ActiveRecord
::
Migration
def
change
add_index
:milestones
,
:title
add_index
:labels
,
:title
end
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