Skip to content

Commit

Permalink
tag searching that is deeply suboptimal on the people index
Browse files Browse the repository at this point in the history
  • Loading branch information
cromulus committed Aug 17, 2016
1 parent 80afeb6 commit ccf40af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 9 additions & 4 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<%- model_class = Person -%>
<div class="row page-header">
<div class="span10">
<div class="span2">
<h1><%=t '.title', :default => "People" %></h1>
</div>
<div class='span1'>
<%= link_to 'all', {}, :class => 'btn btn-mini' %>
<div class='span2'>
<label for="tags">Tags</label>
<%= form_tag '/people', method: :get %>
<%= text_field_tag :tags,
params[:tags],
class: 'tokenfield input-small span4',
id:'tag-field',
data: { search_url: '/taggings/search?q=%QUERY',
submit_id: 'tag-field',
submit_on_tag: true,
pre_populate: @tags
}
%>
</div>
<div class='span1'>
<%= link_to 'not verified', params.merge({not_verified:true}), :class => 'btn btn-mini' %>
<div class="span3">
<%= submit_tag "Search", :name => nil, :class => "btn btn-primary pull-right" %>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions provision_new_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ EOL
curl -sSL https://get.rvm.io | bash -s stable
echo 'rvm_trust_rvmrcs_flag=1' >> ~/.rvmrc
source /home/logan/.rvm/scripts/rvm
rvm install 2.2.4
rvm use 2.2.4@`echo $RAILS_ENV` --create
rvm install 2.2.5
rvm use 2.2.5@`echo $RAILS_ENV` --create
rvm @global do gem install backup bundler rake whenever
ln -s /var/www/logan-`echo $RAILS_ENV`/current `echo $RAILS_ENV`
exit # back to root.
Expand Down

0 comments on commit ccf40af

Please sign in to comment.