Optimize DB accesses for users info
This commit is contained in:
@@ -168,7 +168,7 @@ class Databap extends PhpObject
|
||||
|
||||
//Variables
|
||||
private $iUserId;
|
||||
private $asUserInfo;
|
||||
private $asUsersInfo;
|
||||
private $sLanguage;
|
||||
|
||||
/**
|
||||
@@ -361,7 +361,7 @@ class Databap extends PhpObject
|
||||
private function setUserId($iUserId)
|
||||
{
|
||||
$this->iUserId = $iUserId;
|
||||
$this->asUserInfo = ($iUserId>0)?$this->getUserInfo($iUserId):array();
|
||||
$this->setUserInfo();
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
@@ -820,7 +820,7 @@ class Databap extends PhpObject
|
||||
//Extract extra data
|
||||
$asProc = $oProcedure->getProcedure();
|
||||
$iNewProcId = $asProc['proc_id'];
|
||||
$asUser = $this->getUserInfo($this->getUserId());
|
||||
$asUser = $this->getUserInfo();
|
||||
|
||||
$oResult = array('result'=>'success',
|
||||
'proc_id'=>$iNewProcId,
|
||||
@@ -1196,20 +1196,33 @@ class Databap extends PhpObject
|
||||
return $asTransferredInfo;
|
||||
}
|
||||
|
||||
public function getUserInfo($iUserId, $bJson=false)
|
||||
public function getUserInfo($iUserId=-1, $bJson=false)
|
||||
{
|
||||
$asUserInfo = array();
|
||||
if($iUserId==$this->getUserId() && !empty($this->asUserInfo))
|
||||
if($iUserId==-1) $iUserId = $this->getUserId();
|
||||
|
||||
if(array_key_exists($iUserId, $this->asUsersInfo)) $asUserInfo = $this->asUsersInfo[$iUserId];
|
||||
else
|
||||
{
|
||||
$asUserInfo = $this->asUserInfo;
|
||||
$this->setUserInfo($iUserId);
|
||||
$asUserInfo = $this->getUserInfo($iUserId);
|
||||
}
|
||||
elseif($iUserId > 0)
|
||||
return $bJson?$this->jsonExport($asUserInfo):$asUserInfo;
|
||||
}
|
||||
|
||||
private function setUserInfo($iUserId=-1)
|
||||
{
|
||||
if($iUserId==-1) $iUserId = $this->getUserId();
|
||||
if($iUserId>0)
|
||||
{
|
||||
$asRow = $this->oMySql->selectRow(self::USER_TABLE, $iUserId);
|
||||
if(empty($asRow))$this->addError('Unknown user id: '.$iUserId);
|
||||
else
|
||||
{
|
||||
$sEmail = $this->getUserOptionValue(self::OPT_EMAIL, $iUserId);
|
||||
|
||||
$asCompany = $this->oMySql->selectRow(self::COMP_TABLE, $asRow[MySqlManager::getId(self::COMP_TABLE)]);
|
||||
$asUserInfo = array( 'name'=>self::getNameFormat($asRow['first_name'], $asRow['last_name']),
|
||||
|
||||
$this->asUsersInfo[$iUserId] = array( 'name'=>self::getNameFormat($asRow['first_name'], $asRow['last_name']),
|
||||
'nickname'=>self::getNickNameFormat($this->getChatNickNames($iUserId)),
|
||||
'email'=>$sEmail,
|
||||
'company'=>self::getCompanyFormat($asCompany[MySqlManager::getText(self::COMP_TABLE)]),
|
||||
@@ -1218,12 +1231,12 @@ class Databap extends PhpObject
|
||||
'clearance'=>$asRow['clearance'],
|
||||
'user_led'=>self::getDateFormat($asRow['led'], self::DATE_FORMAT));
|
||||
}
|
||||
return $bJson?$this->jsonExport($asUserInfo):$asUserInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private function getUserClearance()
|
||||
{
|
||||
$asUserInfo = $this->getUserInfo($this->getUserId());
|
||||
$asUserInfo = $this->getUserInfo();
|
||||
return $asUserInfo['clearance'];
|
||||
}
|
||||
|
||||
@@ -1511,7 +1524,7 @@ class Databap extends PhpObject
|
||||
$asMessages[$iChanId] = $this->oMySql->selectValue(self::CHAN_TABLE, MySqlManager::getText(self::CHAN_TABLE), $iChanId);
|
||||
}
|
||||
$sStatus = $this->getUserOptionValue(self::OPT_STATUS);
|
||||
$asUserInfo = $this->getUserInfo($this->getUserId());
|
||||
$asUserInfo = $this->getUserInfo();
|
||||
foreach($asMessages as $iChanId=>$sMsgChanName)
|
||||
{
|
||||
$asPm = $this->isPmChan($sMsgChanName);
|
||||
@@ -1521,7 +1534,6 @@ class Databap extends PhpObject
|
||||
//Send invites to attendees
|
||||
if(!empty($asAttendees))
|
||||
{
|
||||
$asUserInfo = $this->getUserInfo($this->getUserId());
|
||||
foreach($asAttendees as $sAttendee)
|
||||
{
|
||||
if($this->checkChanAuth($sSafeChanName, $sAttendee))
|
||||
@@ -1830,7 +1842,7 @@ class Databap extends PhpObject
|
||||
private function sendPM($iUserIdTo, $sMessage)
|
||||
{
|
||||
$bSuccess = false;
|
||||
$asUserFrom = $this->getUserInfo($this->getUserId());
|
||||
$asUserFrom = $this->getUserInfo();
|
||||
$asUserTo = $this->getUserInfo($iUserIdTo);
|
||||
$sFrom = $asUserFrom['name'].' <www-data@lutran.fr>';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user