Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Fix Monocle/Alternative out of memory with KEEP_GYM_HISTORY
Browse files Browse the repository at this point in the history
When `KEEP_GYM_HISTORY` is on in Monocle/Alternative config, the `fort_sighting` and `raid` may contain multiple records of the same gym. Only the latest gym / fort status should be retrieved to avoid out of memory problem.
  • Loading branch information
j16sdiz authored Jan 30, 2018
1 parent b3ec89c commit a4de066
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Monocle_Alternate.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function query_gyms($conds, $params)
{
global $db;

$query = "SELECT f.external_id AS gym_id,
$query = "SELECT
f.external_id AS gym_id,
fs.last_modified AS last_modified,
updated AS last_scanned,
f.lat AS latitude,
Expand All @@ -235,8 +236,8 @@ public function query_gyms($conds, $params)
r.move_1 AS raid_pokemon_move_1,
r.move_2 AS raid_pokemon_move_2
FROM forts f
LEFT JOIN fort_sightings fs ON fs.fort_id = f.id
LEFT JOIN raids r ON r.fort_id = f.id
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= extract(epoch from now()))
WHERE :conditions";

$query = str_replace(":conditions", join(" AND ", $conds), $query);
Expand Down

0 comments on commit a4de066

Please sign in to comment.