Fix Monocle/Alternative out of memory with KEEP_GYM_HISTORY#78
Fix Monocle/Alternative out of memory with KEEP_GYM_HISTORY#78j16sdiz wants to merge 2 commits intoGlennmen:developfrom
Conversation
lib/Monocle_Alternate.php
Outdated
| 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())) |
There was a problem hiding this comment.
I would recommend using a PHP function to get time() and pass that through as a parameter as extract(epoch from now()) is not supported on MySQL, and conversely UNIX_TIMESTAMP() is not supported in Postgres
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.
|
@CalamityJames fixed |
123FLO321
left a comment
There was a problem hiding this comment.
Working fine for me with KEEP_GYM_HISTORY true
Glennmen
left a comment
There was a problem hiding this comment.
This PR should get merged asap, more people are running Monocle Alternative with KEEP_GYM_HISTORY.
The current queries are optimised for Monocle Alternative with KEEP_GYM_HISTORY = false, so we would want to keep those queries for performance improvement.
I was thinking about a config option to switch between KEEP_GYM_HISTORY true/false queries, unless you have a better suggestion.
|
Actually, the |
|
@j16sdiz I think you are right about |
|
Can someone with KEEP_GYMHISTORY = False run a performance test on: vs I did a test with f.id = 1...20 (uncached) on this and got the following result |
|
@Glennmen fixed |
|
@123FLO321 There is a 6% to 8% perfomance degrade. |
| if ($alternateKeepGymHistory) { | ||
| $query = str_replace(":fort_condition", "fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)", $query); | ||
| } else { | ||
| $query = str_replace(":fort_condition", "1=1", $query); |
There was a problem hiding this comment.
I don't like the 1=1 check.
Maybe include the AND inside :fort_condition and replace it with an empty string if $alternateKeepGymHistory is false?
When
KEEP_GYM_HISTORYis on in Monocle/Alternative config, thefort_sightingandraidmay contain multiple records of the same gym. Only the latest gym / fort status should be retrieved to avoid out of memory problem.