mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Refactor getTopPlayers function
* Option to getTopPlayers by balance * use Cache::remember
This commit is contained in:
parent
35dfaa28ed
commit
c769962e39
@ -1090,20 +1090,16 @@ function csrfProtect(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTopPlayers($limit = 5) {
|
function getTopPlayers($limit = 5, $skill = 'level') {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$cache = Cache::getInstance();
|
if ($skill === 'level') {
|
||||||
if($cache->enabled()) {
|
$skill = 'experience';
|
||||||
$tmp = '';
|
|
||||||
if($cache->fetch('top_' . $limit . '_level', $tmp)) {
|
|
||||||
$players = unserialize($tmp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($players)) {
|
return Cache::remember("top_{$limit}_{$skill}", 2 * 60, function () use ($db, $limit, $skill) {
|
||||||
$columns = [
|
$columns = [
|
||||||
'id', 'name', 'level', 'vocation', 'experience',
|
'id', 'name', 'level', 'vocation', 'experience', 'balance',
|
||||||
'looktype', 'lookhead', 'lookbody', 'looklegs', 'lookfeet'
|
'looktype', 'lookhead', 'lookbody', 'looklegs', 'lookfeet'
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -1115,14 +1111,14 @@ function getTopPlayers($limit = 5) {
|
|||||||
$columns[] = 'online';
|
$columns[] = 'online';
|
||||||
}
|
}
|
||||||
|
|
||||||
$players = Player::query()
|
return Player::query()
|
||||||
->select($columns)
|
->select($columns)
|
||||||
->withOnlineStatus()
|
->withOnlineStatus()
|
||||||
->notDeleted()
|
->notDeleted()
|
||||||
->where('group_id', '<', setting('core.highscores_groups_hidden'))
|
->where('group_id', '<', setting('core.highscores_groups_hidden'))
|
||||||
->whereNotIn('id', setting('core.highscores_ids_hidden'))
|
->whereNotIn('id', setting('core.highscores_ids_hidden'))
|
||||||
->where('account_id', '!=', 1)
|
->where('account_id', '!=', 1)
|
||||||
->orderByDesc('experience')
|
->orderByDesc($skill)
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function ($e, $i) {
|
->map(function ($e, $i) {
|
||||||
@ -1134,13 +1130,7 @@ function getTopPlayers($limit = 5) {
|
|||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
});
|
||||||
if($cache->enabled()) {
|
|
||||||
$cache->set('top_' . $limit . '_level', serialize($players), 120);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteDirectory($dir, $ignore = array(), $contentOnly = false) {
|
function deleteDirectory($dir, $ignore = array(), $contentOnly = false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user