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

Commit a4de066

Browse files
authored
Fix Monocle/Alternative out of memory with KEEP_GYM_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.
1 parent b3ec89c commit a4de066

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/Monocle_Alternate.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public function query_gyms($conds, $params)
216216
{
217217
global $db;
218218

219-
$query = "SELECT f.external_id AS gym_id,
219+
$query = "SELECT
220+
f.external_id AS gym_id,
220221
fs.last_modified AS last_modified,
221222
updated AS last_scanned,
222223
f.lat AS latitude,
@@ -235,8 +236,8 @@ public function query_gyms($conds, $params)
235236
r.move_1 AS raid_pokemon_move_1,
236237
r.move_2 AS raid_pokemon_move_2
237238
FROM forts f
238-
LEFT JOIN fort_sightings fs ON fs.fort_id = f.id
239-
LEFT JOIN raids r ON r.fort_id = f.id
239+
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))
240+
LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= extract(epoch from now()))
240241
WHERE :conditions";
241242

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

0 commit comments

Comments
 (0)