Commit aedd2cfa authored by Douwe Maan's avatar Douwe Maan

Use Gitlab::SQL::Pattern where appropriate

parent b355ebc4
...@@ -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
......
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
......
...@@ -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
......
...@@ -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
......
...@@ -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
......
...@@ -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?
......
...@@ -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
...@@ -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(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment