add caching of users by username to improve performance

pull/3065/head
Isaac Connor 2020-10-12 11:25:20 -04:00
parent 3646a66168
commit 66a8d3876d
1 changed files with 10 additions and 4 deletions

View File

@ -49,6 +49,7 @@ if ( ! $result ) return;
$current_session = $_SESSION;
zm_session_start();
$user_cache = array();
while ( $row = $result->fetch(PDO::FETCH_ASSOC) ) {
$_SESSION = array();
if ( ! session_decode($row['data']) ) {
@ -63,10 +64,15 @@ while ( $row = $result->fetch(PDO::FETCH_ASSOC) ) {
# Not logged in
continue;
}
$user = ZM\User::find_one(array('Username'=>$_SESSION['username']));
if ( ! $user ) {
ZM\Logger::Debug('User not found for ' . $_SESSION['username']);
continue;
if ( isset($user_cache[$_SESSION['username']]) ) {
$user = $user_cache[$_SESSION['username']];
} else {
$user = ZM\User::find_one(array('Username'=>$_SESSION['username']));
if ( ! $user ) {
ZM\Logger::Debug('User not found for ' . $_SESSION['username']);
continue;
}
$user_cache[$_SESSION['username']] = $user;
}
echo '