Skip to content
Permalink
Browse files

Audit Plugin: Reduce Lookups

Reduce the number of calls we make to the database for users or agents loggin in or out of the helpdesk.
  • Loading branch information...
aydreeihn committed Sep 24, 2019
1 parent 203c716 commit 54a175a8bd78685c1aac81cea12da3e31eb06e8f
Showing with 13 additions and 12 deletions.
  1. +6 −12 include/class.auth.php
  2. +7 −0 include/class.client.php
@@ -683,7 +683,7 @@ function login($user, $bk) {
$user->getUserName(), $user->getId(), $_SERVER['REMOTE_ADDR']);
$ost->logDebug(_S('User login'), $msg);
$u = User::lookup($user->getId());
$u = $user->getSessionUser()->getUser();
$type = array('type' => 'login');
Signal::send('person.login', $u, $type);
@@ -723,7 +723,7 @@ static function signOut($user) {
sprintf(_S("%s logged out [%s]" /* Tokens are <username> and <ip> */),
$user->getUserName(), $_SERVER['REMOTE_ADDR']));
$u = User::lookup($user->getId());
$u = $user->getSessionUser()->getUser();
$type = array('type' => 'logout');
Signal::send('person.logout', $u, $type);
}
@@ -906,14 +906,9 @@ function authstrike($credentials) {
$alert, $admin_alert);
if ($username) {
$staffId = Staff::objects()->filter(array('username'=>$username))->values_flat('staff_id')->first();
if ($staffId)
$staff = Staff::lookup($staffId[0]);
if ($staff) {
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}
$agent = Staff::lookup($username);
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}
return new AccessDenied(__('Forgot your login info? Contact Admin.'));
@@ -986,9 +981,8 @@ function authstrike($credentials) {
$user = User::lookup($id);
if ($user) {
$u = User::lookup($user->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $u, $type);
Signal::send('person.login', $user, $type);
}
}
@@ -312,6 +312,13 @@ function getAccount() {
return $this->_account;
}
function getUser() {
if ($this->user === false)
$this->user = User::lookup($this->getId());
return $this->user;
}
function getLanguage($flags=false) {
if ($acct = $this->getAccount())
return $acct->getLanguage($flags);

0 comments on commit 54a175a

Please sign in to comment.
You can’t perform that action at this time.