mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 17:59:22 +02:00
Optimizations
This commit is contained in:
parent
813de7eb3c
commit
d8a70a3da6
@ -984,28 +984,23 @@ function unsetSession($key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTopPlayers($limit = 5) {
|
function getTopPlayers($limit = 5) {
|
||||||
global $config, $db;
|
global $db;
|
||||||
|
|
||||||
$cache = Cache::getInstance();
|
$cache = Cache::getInstance();
|
||||||
$fetch_from_db = true;
|
if($cache->enabled()) {
|
||||||
if($cache->enabled())
|
|
||||||
{
|
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($cache->fetch('top_' . $limit . '_level', $tmp))
|
if($cache->fetch('top_' . $limit . '_level', $tmp)) {
|
||||||
{
|
|
||||||
$players = unserialize($tmp);
|
$players = unserialize($tmp);
|
||||||
$fetch_from_db = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($fetch_from_db)
|
if (!isset($players)) {
|
||||||
{
|
|
||||||
$deleted = 'deleted';
|
$deleted = 'deleted';
|
||||||
if($db->hasColumn('players', 'deletion'))
|
if($db->hasColumn('players', 'deletion'))
|
||||||
$deleted = 'deletion';
|
$deleted = 'deletion';
|
||||||
|
|
||||||
$is_tfs10 = $db->hasTable('players_online');
|
$is_tfs10 = $db->hasTable('players_online');
|
||||||
$players = $db->query('SELECT `id`, `name`, `level`, `experience`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . $config['highscores_groups_hidden'] . ' AND `id` NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `experience` DESC LIMIT ' . (int)$limit)->fetchAll();
|
$players = $db->query('SELECT `id`, `name`, `level`, `experience`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . config('highscores_groups_hidden') . ' AND `id` NOT IN (' . implode(', ', config('highscores_ids_hidden')) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `experience` DESC LIMIT ' . (int)$limit)->fetchAll();
|
||||||
|
|
||||||
if($is_tfs10) {
|
if($is_tfs10) {
|
||||||
foreach($players as &$player) {
|
foreach($players as &$player) {
|
||||||
@ -1021,9 +1016,10 @@ function getTopPlayers($limit = 5) {
|
|||||||
}
|
}
|
||||||
unset($player);
|
unset($player);
|
||||||
|
|
||||||
if($cache->enabled())
|
if($cache->enabled()) {
|
||||||
$cache->set('top_' . $limit . '_level', serialize($players), 120);
|
$cache->set('top_' . $limit . '_level', serialize($players), 120);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $players;
|
return $players;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user