Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drastically increase loading of trainer page #344

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions core/process/aru.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@
$ranking = 0;
if (isset($_GET['name'])) {
$trainer_name = mysqli_real_escape_string($mysqli, $_GET['name']);
$where = " HAVING name LIKE '%".$trainer_name."%'";
$where = " WHERE name LIKE '%".$trainer_name."%'";
}
if (isset($_GET['team']) && $_GET['team'] != 0) {
$team = mysqli_real_escape_string($mysqli, $_GET['team']);
$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
$where .= ($where == "" ? " WHERE" : " AND")." team = ".$team;
}
if (!empty($config->system->trainer_blacklist)) {
$where .= ($where == "" ? " HAVING" : " AND")." name NOT IN ('".implode("','", $config->system->trainer_blacklist)."')";
$where .= ($where == "" ? " WHERE" : " AND")." name NOT IN ('".implode("','", $config->system->trainer_blacklist)."')";
}
if (isset($_GET['page'])) {
$page = mysqli_real_escape_string($mysqli, $_GET['page']);
Expand All @@ -580,13 +580,12 @@
$limit = " LIMIT ".($page * 10).",10 ";


$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
FROM trainer
LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
FROM gympokemon
INNER JOIN (SELECT gymmember.pokemon_uid, gymmember.gym_id FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
GROUP BY trainer.name ".$where.$order.$limit;
$req = "SELECT trainer.name,trainer.team,trainer.level,trainer.last_seen,count(gymmember.pokemon_uid) as 'active',
max(case when gymmember.pokemon_uid is null then 0 else gympokemon.cp end) as 'maxCP'
FROM trainer
LEFT JOIN gympokemon ON trainer.name=gympokemon.trainer_name
LEFT JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid".$where."
GROUP BY trainer.name,trainer.team,trainer.level,trainer.last_seen".$order.$limit;

$result = $mysqli->query($req);
$trainers = array();
Expand All @@ -603,12 +602,11 @@
while ($data = $resultRanking->fetch_object()) {
$trainer->rank = $data->rank;
}
$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, filtered_gymmember.gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".$time_offset."') as deployment_time, '1' AS active
FROM gympokemon INNER JOIN
(SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
WHERE gympokemon.trainer_name='".$trainer->name."'
ORDER BY gympokemon.cp DESC)";
$req = "SELECT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, gymmember.gym_id, CONVERT_TZ(gymmember.deployment_time, '+00:00', '".$time_offset."') as deployment_time, '1' AS active
FROM gympokemon
LEFT JOIN gymmember ON gympokemon.pokemon_uid = gymmember.pokemon_uid
WHERE gymmember.gym_id is not null AND gympokemon.trainer_name='".$trainer->name."'
ORDER BY gympokemon.cp DESC";

$resultPkms = $mysqli->query($req);
$trainer->pokemons = array();
Expand All @@ -620,12 +618,11 @@
}
$trainer->gyms = $active_gyms;

$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".$time_offset."') as deployment_time, '0' AS active
FROM gympokemon LEFT JOIN
(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer->name."'
ORDER BY gympokemon.cp DESC)";
$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(gymmember.deployment_time, '+00:00', '".$time_offset."') as deployment_time, '0' AS active
FROM gympokemon
LEFT JOIN gymmember ON gympokemon.pokemon_uid = gymmember.pokemon_uid
WHERE gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer->name."'
ORDER BY gympokemon.cp DESC";

$resultPkms = $mysqli->query($req);
while ($resultPkms && $dataPkm = $resultPkms->fetch_object()) {
Expand Down