functions.php: optimize listBoards a bit

This commit is contained in:
Zankaria 2024-12-14 00:15:37 +01:00
parent d97c7f271e
commit 21155cbb06

View file

@ -745,24 +745,23 @@ function hasPermission($action = null, $board = null, $_mod = null) {
function listBoards($just_uri = false) {
global $config;
$just_uri ? $cache_name = 'all_boards_uri' : $cache_name = 'all_boards';
$cache_name = $just_uri ? 'all_boards_uri' : 'all_boards';
if ($config['cache']['enabled'] && ($boards = cache::get($cache_name)))
if ($config['cache']['enabled'] && ($boards = cache::get($cache_name))) {
return $boards;
}
if (!$just_uri) {
$query = query("SELECT * FROM ``boards`` ORDER BY `uri`") or error(db_error());
$query = query('SELECT * FROM ``boards`` ORDER BY `uri`');
$boards = $query->fetchAll();
} else {
$boards = array();
$query = query("SELECT `uri` FROM ``boards``") or error(db_error());
while ($board = $query->fetchColumn()) {
$boards[] = $board;
}
$query = query('SELECT `uri` FROM ``boards``');
$boards = $query->fetchAll(\PDO::FETCH_COLUMN);
}
if ($config['cache']['enabled'])
if ($config['cache']['enabled']) {
cache::set($cache_name, $boards);
}
return $boards;
}