BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8cc4a39b
Commit
8cc4a39b
authored
Mar 24, 2017
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '22145-slow-search' into 'master'
Simplify projects, merge requests search queries See merge request !10053
parents
d561881b
df0603cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
11 deletions
+8
-11
merge_request.rb
app/models/merge_request.rb
+4
-2
project.rb
app/models/project.rb
+4
-9
No files found.
app/models/merge_request.rb
View file @
8cc4a39b
...
...
@@ -154,8 +154,10 @@ class MergeRequest < ActiveRecord::Base
#
# Returns an ActiveRecord::Relation.
def
self
.
in_projects
(
relation
)
source
=
where
(
source_project_id:
relation
).
select
(
:id
)
target
=
where
(
target_project_id:
relation
).
select
(
:id
)
# unscoping unnecessary conditions that'll be applied
# when executing `where("merge_requests.id IN (#{union.to_sql})")`
source
=
unscoped
.
where
(
source_project_id:
relation
).
select
(
:id
)
target
=
unscoped
.
where
(
target_project_id:
relation
).
select
(
:id
)
union
=
Gitlab
::
SQL
::
Union
.
new
([
source
,
target
])
where
(
"merge_requests.id IN (
#{
union
.
to_sql
}
)"
)
...
...
app/models/project.rb
View file @
8cc4a39b
...
...
@@ -314,20 +314,15 @@ class Project < ActiveRecord::Base
ntable
=
Namespace
.
arel_table
pattern
=
"%
#{
query
}
%"
projects
=
select
(
:id
).
where
(
# unscoping unnecessary conditions that'll be applied
# when executing `where("projects.id IN (#{union.to_sql})")`
projects
=
unscoped
.
select
(
:id
).
where
(
ptable
[
:path
].
matches
(
pattern
).
or
(
ptable
[
:name
].
matches
(
pattern
)).
or
(
ptable
[
:description
].
matches
(
pattern
))
)
# We explicitly remove any eager loading clauses as they're:
#
# 1. Not needed by this query
# 2. Combined with .joins(:namespace) lead to all columns from the
# projects & namespaces tables being selected, leading to a SQL error
# due to the columns of all UNION'd queries no longer being the same.
namespaces
=
select
(
:id
).
except
(
:includes
).
namespaces
=
unscoped
.
select
(
:id
).
joins
(
:namespace
).
where
(
ntable
[
:name
].
matches
(
pattern
))
...
...
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