Fix some performance issues

This commit is contained in:
RainLoop Team 2014-06-23 20:14:47 +04:00
parent 5b465f5337
commit 40a0f8b821
5 changed files with 56 additions and 8 deletions

View file

@ -2272,6 +2272,8 @@ class ImapClient extends \MailSo\Net\NetClient
$this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. $this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE); ' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE);
$this->bRunningCallback = true;
try try
{ {
\call_user_func($this->aFetchCallbacks[$sFetchKey], \call_user_func($this->aFetchCallbacks[$sFetchKey],
@ -2330,6 +2332,8 @@ class ImapClient extends \MailSo\Net\NetClient
} }
\MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen); \MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen);
$this->bRunningCallback = false;
} }
return $bResult; return $bResult;

View file

@ -18,6 +18,11 @@ abstract class NetClient
*/ */
protected $bUnreadBuffer; protected $bUnreadBuffer;
/**
* @var bool
*/
protected $bRunningCallback;
/** /**
* @var string * @var string
*/ */
@ -63,6 +68,11 @@ abstract class NetClient
*/ */
protected $oLogger; protected $oLogger;
/**
* @var bool
*/
public $__AUTOLOGOUT__;
/** /**
* @access protected * @access protected
*/ */
@ -70,8 +80,11 @@ abstract class NetClient
{ {
$this->rConnect = null; $this->rConnect = null;
$this->bUnreadBuffer = false; $this->bUnreadBuffer = false;
$this->bRunningCallback = false;
$this->oLogger = null; $this->oLogger = null;
$this->__AUTOLOGOUT__ = true;
$this->sResponseBuffer = ''; $this->sResponseBuffer = '';
$this->iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE; $this->iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
@ -92,9 +105,16 @@ abstract class NetClient
public function __destruct() public function __destruct()
{ {
try try
{
if ($this->__AUTOLOGOUT__)
{ {
$this->LogoutAndDisconnect(); $this->LogoutAndDisconnect();
} }
else
{
$this->Disconnect();
}
}
catch (\Exception $oException) {} catch (\Exception $oException) {}
} }
@ -257,7 +277,7 @@ abstract class NetClient
*/ */
public function LogoutAndDisconnect() public function LogoutAndDisconnect()
{ {
if (\method_exists($this, 'Logout') && !$this->bUnreadBuffer) if (\method_exists($this, 'Logout') && !$this->bUnreadBuffer && !$this->bRunningCallback)
{ {
$this->Logout(); $this->Logout();
} }

View file

@ -407,6 +407,8 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->writeLog('Message data.', \MailSo\Log\Enumerations\Type::NOTE); $this->writeLog('Message data.', \MailSo\Log\Enumerations\Type::NOTE);
$this->bRunningCallback = true;
while (!\feof($rDataStream)) while (!\feof($rDataStream))
{ {
$sBuffer = \fgets($rDataStream); $sBuffer = \fgets($rDataStream);
@ -434,6 +436,8 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->sendRequestWithCheck('.', 250); $this->sendRequestWithCheck('.', 250);
$this->bRunningCallback = false;
$this->bData = true; $this->bData = true;
return $this; return $this;

View file

@ -270,6 +270,29 @@ class Actions
return $oResult; return $oResult;
} }
/**
* @return void
*/
public function BootStart()
{
if (defined('APP_INSTALLED_START') && defined('APP_INSTALLED_VERSION') &&
APP_INSTALLED_START && !APP_INSTALLED_VERSION)
{
$this->KeenIO('Install');
}
}
/**
* @return void
*/
public function BootEnd()
{
if ($this->MailClient()->IsLoggined())
{
$this->MailClient()->LogoutAndDisconnect();
}
}
/** /**
* @return string * @return string
*/ */

View file

@ -104,13 +104,9 @@ class Service
return $this; return $this;
} }
$this->oActions->ParseQueryAuthString(); $this->oActions->BootStart();
if (defined('APP_INSTALLED_START') && defined('APP_INSTALLED_VERSION') && $this->oActions->ParseQueryAuthString();
APP_INSTALLED_START && !APP_INSTALLED_VERSION)
{
$this->oActions->KeenIO('Install');
}
$bCached = false; $bCached = false;
$sResult = ''; $sResult = '';
@ -219,6 +215,7 @@ class Service
echo $sResult; echo $sResult;
unset($sResult); unset($sResult);
$this->oActions->BootEnd();
return $this; return $this;
} }