Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 1881d6b

Browse files
committed
Cache domain name to speed up sending process
`getDomain()` was previously called several times for a single email, possibly leading to several SQL queries for each call
1 parent eb9a7a1 commit 1881d6b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Classes/Mailer.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ class Mailer
4343
private $substitutor;
4444

4545
/**
46-
* Constructor that set up basic internal datastructures. Do not call directly
46+
* Cached domain name
47+
*
48+
* @var string
49+
*/
50+
private $domain;
51+
52+
/**
53+
* Constructor that set up basic internal data structures. Do not call directly
4754
*/
4855
public function __construct()
4956
{
@@ -70,7 +77,7 @@ public function getHtml()
7077
public function getPlain()
7178
{
7279
$plainConverter = $this->newsletter->getPlainConverterInstance();
73-
$plainText = $plainConverter->getPlaintext($this->getHtml(), $this->newsletter->getDomain());
80+
$plainText = $plainConverter->getPlaintext($this->getHtml(), $this->domain);
7481

7582
return $plainText;
7683
}
@@ -87,7 +94,8 @@ public function setNewsletter(Newsletter $newsletter, $language = null)
8794
{
8895
// When sending newsletter via scheduler (so via CLI mode) realurl cannot guess
8996
// the domain name by himself, so we help him by filling HTTP_HOST variable
90-
$_SERVER['HTTP_HOST'] = $newsletter->getDomain();
97+
$this->domain = $newsletter->getDomain();
98+
$_SERVER['HTTP_HOST'] = $this->domain;
9199
$_SERVER['SCRIPT_NAME'] = '/index.php';
92100

93101
$this->siteUrl = $newsletter->getBaseUrl() . '/';
@@ -419,7 +427,7 @@ public function createMessage(Email $email)
419427

420428
// Specify message-id for bounce identification
421429
$msgId = $message->getHeaders()->get('Message-ID');
422-
$msgId->setId($email->getAuthCode() . '@' . $this->newsletter->getDomain());
430+
$msgId->setId($email->getAuthCode() . '@' . $this->domain);
423431

424432
// Build plaintext
425433
$plain = $this->getPlain();

0 commit comments

Comments
 (0)