03417456f0
By using a JOIN we can remove the need for using 2 separate queries to find a project by its namespace. Combined with an index (only needed for PostgreSQL) this reduces the query time from ~245 ms (~520 ms for the first call) down to roughly 10 ms (~15 ms for the first call).
28 lines
747 B
Ruby
28 lines
747 B
Ruby
# Concern for querying columns with specific case sensitivity handling.
|
|
module CaseSensitivity
|
|
extend ActiveSupport::Concern
|
|
|
|
module ClassMethods
|
|
# Queries the given columns regardless of the casing used.
|
|
#
|
|
# Unlike other ActiveRecord methods this method only operates on a Hash.
|
|
def iwhere(params)
|
|
criteria = self
|
|
cast_lower = Gitlab::Database.postgresql?
|
|
|
|
params.each do |key, value|
|
|
column = ActiveRecord::Base.connection.quote_table_name(key)
|
|
|
|
if cast_lower
|
|
condition = "LOWER(#{column}) = LOWER(:value)"
|
|
else
|
|
condition = "#{column} = :value"
|
|
end
|
|
|
|
criteria = criteria.where(condition, value: value)
|
|
end
|
|
|
|
criteria
|
|
end
|
|
end
|
|
end
|