From ccf40af813da76232c94b2bb3c5202b8b24ebb83 Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Wed, 17 Aug 2016 13:04:15 -0400 Subject: [PATCH] tag searching that is deeply suboptimal on the people index --- app/controllers/people_controller.rb | 13 +++++++++---- app/views/people/index.html.erb | 21 ++++++++++++++++----- provision_new_server.sh | 4 ++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e9facb8a9..d86effbb8 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -46,12 +46,16 @@ class PeopleController < ApplicationController # GET /people # GET /people.json def index + @verified_types = Person.uniq.pluck(:verified).select(&:present?) - @people = if params[:not_verified] - Person.paginate(page: params[:page]).order(sort_column + ' ' + sort_direction).where(verified: ['NO', nil]).where(active: true) - else + @people = if params[:tags].blank? || params[:tags] == "" Person.paginate(page: params[:page]).order(sort_column + ' ' + sort_direction).where(active: true) + else + tag_names = params[:tags].split(',').map(&:strip) + tags = Tag.where(name:tag_names) + Person.paginate(page: params[:page]).order(sort_column + ' ' + sort_direction).where(active: true).includes(:tags).where(tags: {id: tags.pluck(:id)}) end + @tags = params[:tags].blank? ? '[]' : Tag.where(name: params[:tags].split(',').map(&:strip)).to_json(methods: [:value, :label, :type]) end # GET /people/1 @@ -268,7 +272,8 @@ def should_skip_janky_auth? end def sort_column - Person.column_names.include?(params[:sort]) ? params[:sort] : 'id' + res = Person.column_names.include?(params[:sort]) ? params[:sort] : 'id' + "people.#{res}" end def sort_direction diff --git a/app/views/people/index.html.erb b/app/views/people/index.html.erb index 5c567ef7c..4c9077d1b 100644 --- a/app/views/people/index.html.erb +++ b/app/views/people/index.html.erb @@ -1,13 +1,24 @@ <%- model_class = Person -%>