diff options
-rw-r--r-- | lib/Service/MailTransmission.php | 15 | ||||
-rw-r--r-- | tests/Integration/Service/MailTransmissionIntegrationTest.php | 4 | ||||
-rw-r--r-- | tests/Unit/Service/MailTransmissionTest.php | 5 |
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/Service/MailTransmission.php b/lib/Service/MailTransmission.php index 729da0374..ea31e5e2e 100644 --- a/lib/Service/MailTransmission.php +++ b/lib/Service/MailTransmission.php @@ -61,6 +61,7 @@ use OCA\Mail\Model\IMessage; use OCA\Mail\Model\NewMessageData; use OCA\Mail\Model\RepliedMessageData; use OCA\Mail\SMTP\SmtpClientFactory; +use OCA\Mail\Support\PerformanceLogger; use OCP\AppFramework\Db\DoesNotExistException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -99,6 +100,9 @@ class MailTransmission implements IMailTransmission { /** @var LoggerInterface */ private $logger; + /** @var PerformanceLogger */ + private $performanceLogger; + /** * @param Folder $userFolder */ @@ -111,7 +115,8 @@ class MailTransmission implements IMailTransmission { IEventDispatcher $eventDispatcher, MailboxMapper $mailboxMapper, MessageMapper $messageMapper, - LoggerInterface $logger) { + LoggerInterface $logger, + PerformanceLogger $performanceLogger) { $this->accountService = $accountService; $this->userFolder = $userFolder; $this->attachmentService = $attachmentService; @@ -122,6 +127,7 @@ class MailTransmission implements IMailTransmission { $this->mailboxMapper = $mailboxMapper; $this->messageMapper = $messageMapper; $this->logger = $logger; + $this->performanceLogger = $performanceLogger; } public function sendMessage(NewMessageData $messageData, @@ -209,10 +215,12 @@ class MailTransmission implements IMailTransmission { * @throws ServiceException */ public function saveDraft(NewMessageData $message, Message $previousDraft = null): array { + $perfLogger = $this->performanceLogger->start('save draft'); $this->eventDispatcher->dispatch( SaveDraftEvent::class, new SaveDraftEvent($message->getAccount(), $message, $previousDraft) ); + $perfLogger->step('emit pre event'); $account = $message->getAccount(); $imapMessage = $account->newMessage(); @@ -244,11 +252,13 @@ class MailTransmission implements IMailTransmission { $mail->setBody($imapMessage->getContent()); } $mail->addHeaderOb(Horde_Mime_Headers_MessageId::create()); + $perfLogger->step('build draft message'); // 'Send' the message try { $transport = new Horde_Mail_Transport_Null(); $mail->send($transport, false, false); + $perfLogger->step('create IMAP message'); // save the message in the drafts folder $client = $this->imapClientFactory->getClient($account); $draftsMailboxId = $account->getMailAccount()->getDraftsMailboxId(); @@ -262,6 +272,7 @@ class MailTransmission implements IMailTransmission { $mail, [Horde_Imap_Client::FLAG_DRAFT] ); + $perfLogger->step('save message on IMAP'); } catch (DoesNotExistException $e) { throw new ServiceException('Drafts mailbox does not exist', 0, $e); } catch (Horde_Exception $e) { @@ -272,7 +283,9 @@ class MailTransmission implements IMailTransmission { DraftSavedEvent::class, new DraftSavedEvent($account, $message, $previousDraft) ); + $perfLogger->step('emit post event'); + $perfLogger->end(); return [$account, $draftsMailbox, $newUid]; } diff --git a/tests/Integration/Service/MailTransmissionIntegrationTest.php b/tests/Integration/Service/MailTransmissionIntegrationTest.php index c75441863..8bf24820b 100644 --- a/tests/Integration/Service/MailTransmissionIntegrationTest.php +++ b/tests/Integration/Service/MailTransmissionIntegrationTest.php @@ -42,6 +42,7 @@ use OCA\Mail\Service\AccountService; use OCA\Mail\Service\Attachment\UploadedFile; use OCA\Mail\Service\MailTransmission; use OCA\Mail\SMTP\SmtpClientFactory; +use OCA\Mail\Support\PerformanceLogger; use OCA\Mail\Tests\Integration\Framework\ImapTest; use OCA\Mail\Tests\Integration\TestCase; use OCP\EventDispatcher\IEventDispatcher; @@ -112,7 +113,8 @@ class MailTransmissionIntegrationTest extends TestCase { OC::$server->query(IEventDispatcher::class), OC::$server->query(MailboxMapper::class), OC::$server->query(MessageMapper::class), - OC::$server->query(LoggerInterface::class) + OC::$server->query(LoggerInterface::class), + OC::$server->query(PerformanceLogger::class) ); } diff --git a/tests/Unit/Service/MailTransmissionTest.php b/tests/Unit/Service/MailTransmissionTest.php index ef37d9c2b..cca1ecfef 100644 --- a/tests/Unit/Service/MailTransmissionTest.php +++ b/tests/Unit/Service/MailTransmissionTest.php @@ -43,6 +43,7 @@ use OCA\Mail\Model\RepliedMessageData; use OCA\Mail\Service\AccountService; use OCA\Mail\Service\MailTransmission; use OCA\Mail\SMTP\SmtpClientFactory; +use OCA\Mail\Support\PerformanceLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use PHPUnit\Framework\MockObject\MockObject; @@ -96,6 +97,7 @@ class MailTransmissionTest extends TestCase { $this->mailboxMapper = $this->createMock(MailboxMapper::class); $this->messageMapper = $this->createMock(MessageMapper::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->performanceLogger = $this->createMock(PerformanceLogger::class); $this->transmission = new MailTransmission( $this->userFolder, @@ -107,7 +109,8 @@ class MailTransmissionTest extends TestCase { $this->eventDispatcher, $this->mailboxMapper, $this->messageMapper, - $this->logger + $this->logger, + $this->performanceLogger ); } |