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