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 { ...@@ -48,10 +48,10 @@ class FileLog extends Log {
private $log_to_user_file = false; 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 * @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() { private function getLogToUserFile() {
if ($this->log_to_user_file === false) { if ($this->log_to_user_file === false) {
......
...@@ -67,6 +67,12 @@ abstract class Log { ...@@ -67,6 +67,12 @@ abstract class Log {
*/ */
protected $specialLogUsers = array(); protected $specialLogUsers = array();
/**
* Only used as a cache value for IsUserInSpecialLogUsers function
* @var array
*/
private $isUserInSpecialLogUsers = array();
/** /**
* @var array * @var array
*/ */
...@@ -155,8 +161,12 @@ abstract class Log { ...@@ -155,8 +161,12 @@ abstract class Log {
* @return bool * @return bool
*/ */
public function IsUserInSpecialLogUsers($user) { public function IsUserInSpecialLogUsers($user) {
if ($this->HasSpecialLogUsers()) { if (isset($this->isUserInSpecialLogUsers[$user])) {
return in_array($user, $this->GetSpecialLogUsers()); return true;
}
if ($this->HasSpecialLogUsers() && in_array($user, $this->GetSpecialLogUsers())) {
$this->isUserInSpecialLogUsers[$user] = true;
return true;
} }
return false; return false;
} }
...@@ -175,6 +185,7 @@ abstract class Log { ...@@ -175,6 +185,7 @@ abstract class Log {
* @access public * @access public
*/ */
public function SetSpecialLogUsers(array $value) { public function SetSpecialLogUsers(array $value) {
$this->isUserInSpecialLogUsers = array(); // reset cache
$this->specialLogUsers = $value; $this->specialLogUsers = $value;
} }
...@@ -189,8 +200,8 @@ abstract class Log { ...@@ -189,8 +200,8 @@ abstract class Log {
if ($loglevel <= LOGLEVEL) { if ($loglevel <= LOGLEVEL) {
$this->Write($loglevel, $message); $this->Write($loglevel, $message);
} }
if ($loglevel <= LOGUSERLEVEL && $this->HasSpecialLogUsers()) { if ($loglevel <= LOGUSERLEVEL && $this->IsUserInSpecialLogUsers($this->GetAuthUser())) {
if (RequestProcessor::isUserAuthenticated() && $this->IsUserInSpecialLogUsers($this->GetAuthUser())) { if (RequestProcessor::isUserAuthenticated()) {
// something was logged before the user was authenticated, write this to the log // something was logged before the user was authenticated, write this to the log
if (!empty($this->unauthMessageCache)) { if (!empty($this->unauthMessageCache)) {
foreach ($this->unauthMessageCache as $authcache) { foreach ($this->unauthMessageCache as $authcache) {
...@@ -199,7 +210,8 @@ abstract class Log { ...@@ -199,7 +210,8 @@ abstract class Log {
self::$unAuthCache = array(); self::$unAuthCache = array();
} }
$this->WriteForUser($loglevel, $message); $this->WriteForUser($loglevel, $message);
} else { }
else {
$this->unauthMessageCache[] = array($loglevel, $message); $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