From 173effd7a9b847d156a5548e29ae7df67798c7a2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 13 Jan 2018 17:28:31 -0500 Subject: Fixed incorrect icon eager loading bug on front page A bug was causing a Vigoroth which had evolved into a Slaking to still show up as a Vigoroth on the front page of the engine, even though it showed up properly on its show page. This was deemed to be caused by eager loading. --- app/controllers/pokeviewer/pokemon_controller.rb | 7 +++---- app/jobs/pokeviewer/extract_save_data_job.rb | 2 +- app/models/pokeviewer/pokemon.rb | 5 +---- app/models/pokeviewer/trainer.rb | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index 7a1b9f9..86b0ea6 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb @@ -3,14 +3,13 @@ require_dependency "pokeviewer/application_controller" module Pokeviewer class PokemonController < ApplicationController def index - pokemon = Pokemon.joins(:revisions). + pokemon = Pokemon.joins(:current). order("trainer_id IS NULL DESC"). order(trainer_id: :asc). order(box: :asc). order(slot: :asc). - order("pokeviewer_revisions.sequential_id DESC"). group("pokeviewer_pokemon.uuid"). - includes(:revisions). + includes(:current). chunk do |p| if p.trainer_id.nil? -1 @@ -70,7 +69,7 @@ module Pokeviewer def show @pokemon = Pokemon.includes( :trainer, :location, - revisions: [:species, :item, :move_1, :move_2, :move_3, :move_4] + current: [:species, :item, :move_1, :move_2, :move_3, :move_4] ).find_by_uuid! params[:id] end end diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index d1968af..b0999ef 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb @@ -169,7 +169,7 @@ module Pokeviewer rev.earth_ribbon = param.fetch "earthRibbon", false rev.world_ribbon = param.fetch "worldRibbon", false - if pk.revisions.empty? or rev.diff?(pk.revisions.last) + if pk.revisions.empty? or rev.diff?(pk.current) rev.save! end end diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index db3da5a..012abab 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb @@ -4,6 +4,7 @@ module Pokeviewer extend ActiveModel::Naming has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy + has_one :current, -> { order "sequential_id DESC" }, class_name: "Revision" belongs_to :trainer, optional: true @@ -76,10 +77,6 @@ module Pokeviewer uuid end - def current - revisions.last - end - def outsider? (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) end diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index 281e0aa..0ea12c8 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb @@ -39,11 +39,11 @@ module Pokeviewer validates :box_14_name, presence: true def party - pokemon.party.includes(revisions: [:species]) + pokemon.party.includes(current: [:species]) end def box(n) - pokemon.box(n).includes(revisions: [:species]) + pokemon.box(n).includes(current: [:species]) end def box_name(n) -- cgit 1.4.1