about summary refs log tree commit diff stats
path: root/app/controllers
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-01-14 13:06:18 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-01-14 13:06:18 -0500
commit30cd66e1521bc760df45908adb2f7d3ba6683900 (patch)
treeb730fbfc687516be2e4df95250d02598e9e7fa73 /app/controllers
parent91eeaa33a436ba2233f1fe7509f7c104db1d4533 (diff)
downloadpokeviewer-30cd66e1521bc760df45908adb2f7d3ba6683900.tar.gz
pokeviewer-30cd66e1521bc760df45908adb2f7d3ba6683900.tar.bz2
pokeviewer-30cd66e1521bc760df45908adb2f7d3ba6683900.zip
Cached a Pokémon's latest revision
This removes the need to use a GROUP or DISTINCT in eager-loading Pokémon on the front page. It duplicates data, but provisions are in place to keep the cache up-to-date. When a Pokémon record is updated, it is required that its cache points to the current revision. When a revision is created, it updates the Pokémon's cache to point to it, because a new revision will always be the most recent one, and it is impossible to reorder revisions.

This does not affect the number of queries used on the front page (see #1).

refs #4
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/pokeviewer/pokemon_controller.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index 0e19c6a..f2d2187 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb
@@ -7,8 +7,7 @@ module Pokeviewer
7 order(trainer_id: :asc). 7 order(trainer_id: :asc).
8 order(box: :asc). 8 order(box: :asc).
9 order(slot: :asc). 9 order(slot: :asc).
10 select(:uuid).distinct. 10 joins(:current).
11 order("pokeviewer_revisions.sequential_id DESC").
12 includes(:current). 11 includes(:current).
13 chunk do |p| 12 chunk do |p|
14 if p.trainer_id.nil? 13 if p.trainer_id.nil?