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
Boxiang Sun
gitlab-ce
Commits
aedd2cfa
Commit
aedd2cfa
authored
Nov 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Gitlab::SQL::Pattern where appropriate
parent
b355ebc4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
16 additions
and
25 deletions
+16
-25
app/finders/notes_finder.rb
app/finders/notes_finder.rb
+1
-2
app/models/ci/runner.rb
app/models/ci/runner.rb
+2
-1
app/models/group.rb
app/models/group.rb
+0
-14
app/models/milestone.rb
app/models/milestone.rb
+2
-1
app/models/namespace.rb
app/models/namespace.rb
+2
-1
app/models/note.rb
app/models/note.rb
+5
-0
app/models/snippet.rb
app/models/snippet.rb
+3
-5
app/models/user.rb
app/models/user.rb
+1
-1
No files found.
app/finders/notes_finder.rb
View file @
aedd2cfa
...
...
@@ -104,8 +104,7 @@ class NotesFinder
query
=
@params
[
:search
]
return
notes
unless
query
pattern
=
"%
#{
query
}
%"
notes
.
where
(
Note
.
arel_table
[
:note
].
matches
(
pattern
))
notes
.
search
(
query
)
end
# Notes changed since last fetch
...
...
app/models/ci/runner.rb
View file @
aedd2cfa
module
Ci
class
Runner
<
ActiveRecord
::
Base
extend
Gitlab
::
Ci
::
Model
include
Gitlab
::
SQL
::
Pattern
RUNNER_QUEUE_EXPIRY_TIME
=
60
.
minutes
ONLINE_CONTACT_TIMEOUT
=
1
.
hour
...
...
@@ -60,7 +61,7 @@ module Ci
# Returns an ActiveRecord::Relation.
def
self
.
search
(
query
)
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:token
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
...
...
app/models/group.rb
View file @
aedd2cfa
...
...
@@ -50,20 +50,6 @@ class Group < Namespace
Gitlab
::
Database
.
postgresql?
end
# Searches for groups matching the given query.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# query - The search query as a String
#
# Returns an ActiveRecord::Relation.
def
search
(
query
)
table
=
Namespace
.
arel_table
pattern
=
"%
#{
query
}
%"
where
(
table
[
:name
].
matches
(
pattern
).
or
(
table
[
:path
].
matches
(
pattern
)))
end
def
sort
(
method
)
if
method
==
'storage_size_desc'
# storage_size is a virtual column so we need to
...
...
app/models/milestone.rb
View file @
aedd2cfa
...
...
@@ -13,6 +13,7 @@ class Milestone < ActiveRecord::Base
include
Referable
include
StripAttribute
include
Milestoneish
include
Gitlab
::
SQL
::
Pattern
cache_markdown_field
:title
,
pipeline: :single_line
cache_markdown_field
:description
...
...
@@ -74,7 +75,7 @@ class Milestone < ActiveRecord::Base
# Returns an ActiveRecord::Relation.
def
search
(
query
)
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
...
...
app/models/namespace.rb
View file @
aedd2cfa
...
...
@@ -9,6 +9,7 @@ class Namespace < ActiveRecord::Base
include
Routable
include
AfterCommitQueue
include
Storage
::
LegacyNamespace
include
Gitlab
::
SQL
::
Pattern
# Prevent users from creating unreasonably deep level of nesting.
# The number 20 was taken based on maximum nesting level of
...
...
@@ -87,7 +88,7 @@ class Namespace < ActiveRecord::Base
# Returns an ActiveRecord::Relation
def
search
(
query
)
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:name
].
matches
(
pattern
).
or
(
t
[
:path
].
matches
(
pattern
)))
end
...
...
app/models/note.rb
View file @
aedd2cfa
...
...
@@ -14,6 +14,7 @@ class Note < ActiveRecord::Base
include
ResolvableNote
include
IgnorableColumn
include
Editable
include
Gitlab
::
SQL
::
Pattern
module
SpecialRole
FIRST_TIME_CONTRIBUTOR
=
:first_time_contributor
...
...
@@ -167,6 +168,10 @@ class Note < ActiveRecord::Base
def
has_special_role?
(
role
,
note
)
note
.
special_role
==
role
end
def
search
(
query
)
where
(
arel_table
[
:note
].
matches
(
to_pattern
(
query
)))
end
end
def
cross_reference?
...
...
app/models/snippet.rb
View file @
aedd2cfa
...
...
@@ -9,6 +9,7 @@ class Snippet < ActiveRecord::Base
include
Mentionable
include
Spammable
include
Editable
include
Gitlab
::
SQL
::
Pattern
extend
Gitlab
::
CurrentSettings
...
...
@@ -136,7 +137,7 @@ class Snippet < ActiveRecord::Base
# Returns an ActiveRecord::Relation.
def
search
(
query
)
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[:
file_name
].
matches
(
pattern
)))
end
...
...
@@ -149,10 +150,7 @@ class Snippet < ActiveRecord::Base
#
# Returns an ActiveRecord::Relation.
def
search_code
(
query
)
table
=
Snippet
.
arel_table
pattern
=
"%
#{
query
}
%"
where
(
table
[
:content
].
matches
(
pattern
))
where
(
arel_table
[
:content
].
matches
(
to_pattern
(
query
)))
end
end
end
app/models/user.rb
View file @
aedd2cfa
...
...
@@ -339,7 +339,7 @@ class User < ActiveRecord::Base
def
search_with_secondary_emails
(
query
)
table
=
arel_table
email_table
=
Email
.
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
matched_by_emails_user_ids
=
email_table
.
project
(
email_table
[
:user_id
]).
where
(
email_table
[
:email
].
matches
(
pattern
))
where
(
...
...
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