ZP-765 Added a cache value for IsUserInSpecialLogUsers. Released under the...

ZP-765 Added a cache value for IsUserInSpecialLogUsers. Released under the Affero GNU General Public License (AGPL) version 3.
parent 1b2f035d
......@@ -48,10 +48,10 @@ class FileLog extends Log {
private $log_to_user_file = false;
/**
* Get the log user file. If the parameter is false, it tries to generate it.
* Get the log user file.
*
* @access private
* @return string|bool False if the log user file is not set and could not be generated otherwise string.
* @return string
*/
private function getLogToUserFile() {
if ($this->log_to_user_file === false) {
......
......@@ -67,6 +67,12 @@ abstract class Log {
*/
protected $specialLogUsers = array();
/**
* Only used as a cache value for IsUserInSpecialLogUsers function
* @var array
*/
private $isUserInSpecialLogUsers = array();
/**
* @var array
*/
......@@ -155,8 +161,12 @@ abstract class Log {
* @return bool
*/
public function IsUserInSpecialLogUsers($user) {
if ($this->HasSpecialLogUsers()) {
return in_array($user, $this->GetSpecialLogUsers());
if (isset($this->isUserInSpecialLogUsers[$user])) {
return true;
}
if ($this->HasSpecialLogUsers() && in_array($user, $this->GetSpecialLogUsers())) {
$this->isUserInSpecialLogUsers[$user] = true;
return true;
}
return false;
}
......@@ -175,6 +185,7 @@ abstract class Log {
* @access public
*/
public function SetSpecialLogUsers(array $value) {
$this->isUserInSpecialLogUsers = array(); // reset cache
$this->specialLogUsers = $value;
}
......@@ -189,8 +200,8 @@ abstract class Log {
if ($loglevel <= LOGLEVEL) {
$this->Write($loglevel, $message);
}
if ($loglevel <= LOGUSERLEVEL && $this->HasSpecialLogUsers()) {
if (RequestProcessor::isUserAuthenticated() && $this->IsUserInSpecialLogUsers($this->GetAuthUser())) {
if ($loglevel <= LOGUSERLEVEL && $this->IsUserInSpecialLogUsers($this->GetAuthUser())) {
if (RequestProcessor::isUserAuthenticated()) {
// something was logged before the user was authenticated, write this to the log
if (!empty($this->unauthMessageCache)) {
foreach ($this->unauthMessageCache as $authcache) {
......@@ -199,7 +210,8 @@ abstract class Log {
self::$unAuthCache = array();
}
$this->WriteForUser($loglevel, $message);
} else {
}
else {
$this->unauthMessageCache[] = array($loglevel, $message);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment