From 353b170392892a1f9bdde74550112b5131c99fd2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 3 Oct 2017 22:49:19 -0400 Subject: Optimized front page queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduced the number of queries that the front page runs to 2 queries total: one to get trainer data, and one to get the Pokémon. The latter query selects only the necessary columns, notably ignoring basically everything from the revisions join other than the nickname of the most recent revision. The controller then does the work of chunking the Pokémon into party/boxes, and then into trainers/unaccounted. refs #2 --- app/views/pokeviewer/pokemon/index.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app/views') diff --git a/app/views/pokeviewer/pokemon/index.html.haml b/app/views/pokeviewer/pokemon/index.html.haml index 0be3edd..e1793dc 100644 --- a/app/views/pokeviewer/pokemon/index.html.haml +++ b/app/views/pokeviewer/pokemon/index.html.haml @@ -1,4 +1,4 @@ -- @trainers.each do |trainer| +- @trainers.each do |trainer, party, boxes| .trainer .trainer-info{ class: trainer.game } %h2= trainer.name @@ -6,11 +6,11 @@ .pc-boxes %ul.party.pc-box %h3 Party - - trainer.party.each do |p| + - party.each do |p| %li %span.party-icon= image_tag p.icon_path - %span.party-name= link_to p.revisions.last.nickname, p - - trainer.boxes.each do |box| + %span.party-name= link_to p.nickname, p + - boxes.each do |box| .pc-box %h3= box[:name] %table.pc-contents @@ -23,7 +23,7 @@ - else = link_to image_tag(p.icon_path), p .pc-data.pkv-hover - .pc-data-name= p.revisions.last.nickname + .pc-data-name= p.nickname .pc-data-ot OT/ %span{ class: p.ot_gender }>= p.ot_name @@ -36,7 +36,7 @@ %li.pc-pokemon.pkv-has-hover = link_to image_tag(p.icon_path), p .pc-data.pkv-hover - .pc-data-name= p.revisions.last.nickname + .pc-data-name= p.nickname .pc-data-ot OT/ %span{ class: p.ot_gender }>= p.ot_name -- cgit 1.4.1