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