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
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
Show 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
...
@@ -104,8 +104,7 @@ class NotesFinder
query
=
@params
[
:search
]
query
=
@params
[
:search
]
return
notes
unless
query
return
notes
unless
query
pattern
=
"%
#{
query
}
%"
notes
.
search
(
query
)
notes
.
where
(
Note
.
arel_table
[
:note
].
matches
(
pattern
))
end
end
# Notes changed since last fetch
# Notes changed since last fetch
...
...
app/models/ci/runner.rb
View file @
aedd2cfa
module
Ci
module
Ci
class
Runner
<
ActiveRecord
::
Base
class
Runner
<
ActiveRecord
::
Base
extend
Gitlab
::
Ci
::
Model
extend
Gitlab
::
Ci
::
Model
include
Gitlab
::
SQL
::
Pattern
RUNNER_QUEUE_EXPIRY_TIME
=
60
.
minutes
RUNNER_QUEUE_EXPIRY_TIME
=
60
.
minutes
ONLINE_CONTACT_TIMEOUT
=
1
.
hour
ONLINE_CONTACT_TIMEOUT
=
1
.
hour
...
@@ -60,7 +61,7 @@ module Ci
...
@@ -60,7 +61,7 @@ module Ci
# Returns an ActiveRecord::Relation.
# Returns an ActiveRecord::Relation.
def
self
.
search
(
query
)
def
self
.
search
(
query
)
t
=
arel_table
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:token
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
where
(
t
[
:token
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
end
...
...
app/models/group.rb
View file @
aedd2cfa
...
@@ -50,20 +50,6 @@ class Group < Namespace
...
@@ -50,20 +50,6 @@ class Group < Namespace
Gitlab
::
Database
.
postgresql?
Gitlab
::
Database
.
postgresql?
end
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
)
def
sort
(
method
)
if
method
==
'storage_size_desc'
if
method
==
'storage_size_desc'
# storage_size is a virtual column so we need to
# 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
...
@@ -13,6 +13,7 @@ class Milestone < ActiveRecord::Base
include
Referable
include
Referable
include
StripAttribute
include
StripAttribute
include
Milestoneish
include
Milestoneish
include
Gitlab
::
SQL
::
Pattern
cache_markdown_field
:title
,
pipeline: :single_line
cache_markdown_field
:title
,
pipeline: :single_line
cache_markdown_field
:description
cache_markdown_field
:description
...
@@ -74,7 +75,7 @@ class Milestone < ActiveRecord::Base
...
@@ -74,7 +75,7 @@ class Milestone < ActiveRecord::Base
# Returns an ActiveRecord::Relation.
# Returns an ActiveRecord::Relation.
def
search
(
query
)
def
search
(
query
)
t
=
arel_table
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
end
...
...
app/models/namespace.rb
View file @
aedd2cfa
...
@@ -9,6 +9,7 @@ class Namespace < ActiveRecord::Base
...
@@ -9,6 +9,7 @@ class Namespace < ActiveRecord::Base
include
Routable
include
Routable
include
AfterCommitQueue
include
AfterCommitQueue
include
Storage
::
LegacyNamespace
include
Storage
::
LegacyNamespace
include
Gitlab
::
SQL
::
Pattern
# Prevent users from creating unreasonably deep level of nesting.
# Prevent users from creating unreasonably deep level of nesting.
# The number 20 was taken based on maximum nesting level of
# The number 20 was taken based on maximum nesting level of
...
@@ -87,7 +88,7 @@ class Namespace < ActiveRecord::Base
...
@@ -87,7 +88,7 @@ class Namespace < ActiveRecord::Base
# Returns an ActiveRecord::Relation
# Returns an ActiveRecord::Relation
def
search
(
query
)
def
search
(
query
)
t
=
arel_table
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:name
].
matches
(
pattern
).
or
(
t
[
:path
].
matches
(
pattern
)))
where
(
t
[
:name
].
matches
(
pattern
).
or
(
t
[
:path
].
matches
(
pattern
)))
end
end
...
...
app/models/note.rb
View file @
aedd2cfa
...
@@ -14,6 +14,7 @@ class Note < ActiveRecord::Base
...
@@ -14,6 +14,7 @@ class Note < ActiveRecord::Base
include
ResolvableNote
include
ResolvableNote
include
IgnorableColumn
include
IgnorableColumn
include
Editable
include
Editable
include
Gitlab
::
SQL
::
Pattern
module
SpecialRole
module
SpecialRole
FIRST_TIME_CONTRIBUTOR
=
:first_time_contributor
FIRST_TIME_CONTRIBUTOR
=
:first_time_contributor
...
@@ -167,6 +168,10 @@ class Note < ActiveRecord::Base
...
@@ -167,6 +168,10 @@ class Note < ActiveRecord::Base
def
has_special_role?
(
role
,
note
)
def
has_special_role?
(
role
,
note
)
note
.
special_role
==
role
note
.
special_role
==
role
end
end
def
search
(
query
)
where
(
arel_table
[
:note
].
matches
(
to_pattern
(
query
)))
end
end
end
def
cross_reference?
def
cross_reference?
...
...
app/models/snippet.rb
View file @
aedd2cfa
...
@@ -9,6 +9,7 @@ class Snippet < ActiveRecord::Base
...
@@ -9,6 +9,7 @@ class Snippet < ActiveRecord::Base
include
Mentionable
include
Mentionable
include
Spammable
include
Spammable
include
Editable
include
Editable
include
Gitlab
::
SQL
::
Pattern
extend
Gitlab
::
CurrentSettings
extend
Gitlab
::
CurrentSettings
...
@@ -136,7 +137,7 @@ class Snippet < ActiveRecord::Base
...
@@ -136,7 +137,7 @@ class Snippet < ActiveRecord::Base
# Returns an ActiveRecord::Relation.
# Returns an ActiveRecord::Relation.
def
search
(
query
)
def
search
(
query
)
t
=
arel_table
t
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
to_pattern
(
query
)
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[:
file_name
].
matches
(
pattern
)))
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[:
file_name
].
matches
(
pattern
)))
end
end
...
@@ -149,10 +150,7 @@ class Snippet < ActiveRecord::Base
...
@@ -149,10 +150,7 @@ class Snippet < ActiveRecord::Base
#
#
# Returns an ActiveRecord::Relation.
# Returns an ActiveRecord::Relation.
def
search_code
(
query
)
def
search_code
(
query
)
table
=
Snippet
.
arel_table
where
(
arel_table
[
:content
].
matches
(
to_pattern
(
query
)))
pattern
=
"%
#{
query
}
%"
where
(
table
[
:content
].
matches
(
pattern
))
end
end
end
end
end
end
app/models/user.rb
View file @
aedd2cfa
...
@@ -339,7 +339,7 @@ class User < ActiveRecord::Base
...
@@ -339,7 +339,7 @@ class User < ActiveRecord::Base
def
search_with_secondary_emails
(
query
)
def
search_with_secondary_emails
(
query
)
table
=
arel_table
table
=
arel_table
email_table
=
Email
.
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
))
matched_by_emails_user_ids
=
email_table
.
project
(
email_table
[
:user_id
]).
where
(
email_table
[
:email
].
matches
(
pattern
))
where
(
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