From 40a0f8b821be192e5c4eebbbdb74af2d01116573 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Mon, 23 Jun 2014 20:14:47 +0400 Subject: [PATCH] Fix some performance issues --- .../app/libraries/MailSo/Imap/ImapClient.php | 4 ++++ .../app/libraries/MailSo/Net/NetClient.php | 24 +++++++++++++++++-- .../app/libraries/MailSo/Smtp/SmtpClient.php | 4 ++++ .../0.0.0/app/libraries/RainLoop/Actions.php | 23 ++++++++++++++++++ .../0.0.0/app/libraries/RainLoop/Service.php | 9 +++---- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index 6119ec63a..38f41a6c8 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -2272,6 +2272,8 @@ class ImapClient extends \MailSo\Net\NetClient $this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. ' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE); + $this->bRunningCallback = true; + try { \call_user_func($this->aFetchCallbacks[$sFetchKey], @@ -2330,6 +2332,8 @@ class ImapClient extends \MailSo\Net\NetClient } \MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen); + + $this->bRunningCallback = false; } return $bResult; diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index bb032fbe4..6309ff9dd 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -18,6 +18,11 @@ abstract class NetClient */ protected $bUnreadBuffer; + /** + * @var bool + */ + protected $bRunningCallback; + /** * @var string */ @@ -63,6 +68,11 @@ abstract class NetClient */ protected $oLogger; + /** + * @var bool + */ + public $__AUTOLOGOUT__; + /** * @access protected */ @@ -70,7 +80,10 @@ abstract class NetClient { $this->rConnect = null; $this->bUnreadBuffer = false; + $this->bRunningCallback = false; $this->oLogger = null; + + $this->__AUTOLOGOUT__ = true; $this->sResponseBuffer = ''; @@ -93,7 +106,14 @@ abstract class NetClient { try { - $this->LogoutAndDisconnect(); + if ($this->__AUTOLOGOUT__) + { + $this->LogoutAndDisconnect(); + } + else + { + $this->Disconnect(); + } } catch (\Exception $oException) {} } @@ -257,7 +277,7 @@ abstract class NetClient */ public function LogoutAndDisconnect() { - if (\method_exists($this, 'Logout') && !$this->bUnreadBuffer) + if (\method_exists($this, 'Logout') && !$this->bUnreadBuffer && !$this->bRunningCallback) { $this->Logout(); } diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php index 125f8091e..174e9ffb8 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php @@ -407,6 +407,8 @@ class SmtpClient extends \MailSo\Net\NetClient $this->writeLog('Message data.', \MailSo\Log\Enumerations\Type::NOTE); + $this->bRunningCallback = true; + while (!\feof($rDataStream)) { $sBuffer = \fgets($rDataStream); @@ -434,6 +436,8 @@ class SmtpClient extends \MailSo\Net\NetClient $this->sendRequestWithCheck('.', 250); + $this->bRunningCallback = false; + $this->bData = true; return $this; diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php index 4cb9a68c4..00cf8a96d 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -270,6 +270,29 @@ class Actions 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 */ diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php index ac6fc9f56..c248462e6 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php @@ -104,14 +104,10 @@ class Service return $this; } + $this->oActions->BootStart(); + $this->oActions->ParseQueryAuthString(); - if (defined('APP_INSTALLED_START') && defined('APP_INSTALLED_VERSION') && - APP_INSTALLED_START && !APP_INSTALLED_VERSION) - { - $this->oActions->KeenIO('Install'); - } - $bCached = false; $sResult = ''; @@ -219,6 +215,7 @@ class Service echo $sResult; unset($sResult); + $this->oActions->BootEnd(); return $this; }