Commit aedd2cfa authored by Douwe Maan's avatar Douwe Maan

Use Gitlab::SQL::Pattern where appropriate

parent b355ebc4
......@@ -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
......
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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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?
......
......@@ -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
......@@ -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(
......
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