Add method to search for a list of uploads

parent c12d9e8f
...@@ -9,6 +9,8 @@ module EE ...@@ -9,6 +9,8 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
include ::Gitlab::SQL::Pattern
after_destroy :log_geo_deleted_event after_destroy :log_geo_deleted_event
scope :for_model, ->(model) { where(model_id: model.id, model_type: model.class.name) } scope :for_model, ->(model) { where(model_id: model.id, model_type: model.class.name) }
...@@ -21,6 +23,16 @@ module EE ...@@ -21,6 +23,16 @@ module EE
selective_sync_scope(node).merge(object_storage_scope(node)) selective_sync_scope(node).merge(object_storage_scope(node))
end end
# Searches for a list of uploads based on the query given in `query`.
#
# On PostgreSQL this method uses "ILIKE" to perform a case-insensitive
# search.
#
# query - The search query as a String.
def search(query)
fuzzy_search(query, [:path])
end
private private
# @return [ActiveRecord::Relation<Upload>] scope observing object storage settings of the given node # @return [ActiveRecord::Relation<Upload>] scope observing object storage settings of the given node
......
...@@ -45,7 +45,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry ...@@ -45,7 +45,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry
def self.with_search(query) def self.with_search(query)
return all if query.nil? return all if query.nil?
where(file_id: Geo::Fdw::Upload.search(query)) where(file_id: Upload.search(query).limit(1000).pluck_primary_key)
end end
def self.with_status(status) def self.with_status(status)
......
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