From acb7233346a5bb073ede266ca7a4032a00fa0ff7 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Mon, 26 Oct 2020 15:43:25 +0000 Subject: [PATCH] fast name search by default Re: https://github.com/ipfs/pinning-services-api-spec/pull/66 --- app/controllers/api/v1/pins_controller.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/pins_controller.rb b/app/controllers/api/v1/pins_controller.rb index 5b7af35..970c31a 100644 --- a/app/controllers/api/v1/pins_controller.rb +++ b/app/controllers/api/v1/pins_controller.rb @@ -8,7 +8,19 @@ def index @status = 'pinned' if @status.blank? @scope = current_user.pins.not_deleted.order('created_at DESC').status(@status) - @scope = @scope.name_contains(params[:name]) if params[:name].present? + if params[:name].present? + case params[:match] + when 'iexact' + @scope = @scope.where('name ilike ?', params[:name]) + when 'partial' + @scope = @scope.where('name like ?', "%#{params[:name]}%") + when 'ipartial' + @scope = @scope.where('name ilike ?', "%#{params[:name]}%") + else + @scope = @scope.where(name: params[:name]) + end + end + @scope = @scope.cids(params[:cid].split(',').first(10)) if params[:cid].present? @scope = @scope.before(params[:before]) if params[:before].present? @scope = @scope.after(params[:after]) if params[:after].present?