Having a problem with simplenews module for drupal-6 (It does not send test issues on my site) I looked into the code and saw that there is function simplenews_mail_mail() is called for sending issues for every subscriber, limited by number of issues posted per cron run if "send by cron" is choosen.
Here is the definition of this function from the module:
function simplenews_mail_mail($nid, $vid, $mail, $key = 'node') {
// Get subscription data for recipient and language
$account = new stdClass();
$account->mail = $mail;
$subscription = simplenews_get_subscription($account);
$params['context']['account'] = $subscription;
static $cache;
if(isset($cache["$nid:$vid"])) {
$node = $cache["$nid:$vid"];
}
else {
// Get node data for the mail
$node = node_load($nid, $vid);
$cache["$nid:$vid"] = $node;
}
if (is_object($node)) {
$params['from'] = _simplenews_set_from($node);
$params['context']['newsletter'] = taxonomy_get_term($node->simplenews['tid']);
$params['context']['node'] = $node;
// Send mail
if (module_exists('mimemail')) {
// If mimemail module is installed ALL emails are send via this module.
// drupal_mail() builds the content of the email but does NOT send.
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['formatted'], FALSE);
$plain = $message['params']['context']['node']->simplenews['s_format'] == 'plain';
$message['result'] = mimemail(
$message['from'],
$message['to'],
$message['subject'],
$message['body'],
$plain,
$message['headers'],
$plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
''
);
}
else {
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['address'], TRUE);
}
// Log sent message.
if (variable_get('simplenews_debug', FALSE)) {
if (module_exists('mimemail')) {
$via_mimemail = t('Sent via Mime Mail');
}
//TODO Add line break before %mimemail.
if ($message['result']) {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail), WATCHDOG_DEBUG);
}
else {
watchdog('simplenews', 'Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail), WATCHDOG_ERROR);
}
}
}
else {
watchdog('simplenews', 'Newsletter not send: node does not exist (nid = @nid; vid = @vid).', array('@nid' => $message['nid'], '@vid' => $message['vid']), WATCHDOG_ERROR);
}
return isset($message['result']) ? $message['result'] : FALSE;
}
So there is node_load($nid, $vid); inside of it. And if $vid == NULL then the node object is cached in the node_load. But we allways have $vid not null in our case seems, so if we for example want to send issue to 200 users per cron we have to load the same node object 200 times.
I think we could do the caching in this function like this:
function simplenews_mail_mail($nid, $vid, $mail, $key = 'node') {
// Get subscription data for recipient and language
$account = new stdClass();
$account->mail = $mail;
$subscription = simplenews_get_subscription($account);
$params['context']['account'] = $subscription;
// Get node data for the mail
$node = node_load($nid, $vid);
if (is_object($node)) {
$params['from'] = _simplenews_set_from($node);
$params['context']['newsletter'] = taxonomy_get_term($node->simplenews['tid']);
$params['context']['node'] = $node;
// Send mail
if (module_exists('mimemail')) {
// If mimemail module is installed ALL emails are send via this module.
// drupal_mail() builds the content of the email but does NOT send.
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['formatted'], FALSE);
$plain = $message['params']['context']['node']->simplenews['s_format'] == 'plain';
$message['result'] = mimemail(
$message['from'],
$message['to'],
$message['subject'],
$message['body'],
$plain,
$message['headers'],
$plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
''
);
}
else {
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['address'], TRUE);
}
// Log sent message.
if (variable_get('simplenews_debug', FALSE)) {
if (module_exists('mimemail')) {
$via_mimemail = t('Sent via Mime Mail');
}
//TODO Add line break before %mimemail.
if ($message['result']) {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail), WATCHDOG_DEBUG);
}
else {
watchdog('simplenews', 'Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array('%type' => $key, '%to' => $message['to'], '%subject' => $message['subject'], '%mimemail' => $via_mimemail), WATCHDOG_ERROR);
}
}
}
else {
watchdog('simplenews', 'Newsletter not send: node does not exist (nid = @nid; vid = @vid).', array('@nid' => $message['nid'], '@vid' => $message['vid']), WATCHDOG_ERROR);
}
return isset($message['result']) ? $message['result'] : FALSE;
}
Needs to be watched by more experienced eye.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | simplenews.466030.patch | 1.26 KB | sutharsan |
Comments
Comment #1
netbear commentedWhoops I mixed the places for code peaces - all should be reversed like this
Having a problem with simplenews module for drupal-6 (It does not send test issues on my site) I looked into the code and saw that there is function simplenews_mail_mail() is called for sending issues for every subscriber, limited by number of issues posted per cron run if "send by cron" is choosen.
Here is the definition of this function from the module:
So there is node_load($nid, $vid); inside of it. And if $vid == NULL then the node object is cached in the node_load. But we allways have $vid not null in our case seems, so if we for example want to send issue to 200 users per cron we have to load the same node object 200 times.
I think we could do the caching in this function like this:
Needs to be watched by more experienced eye.
Comment #2
sutharsan commentedI need to look at this.
Comment #3
sutharsan commentednetbear, thanks for your suggestion. I was not aware of this behaviour of node_load(). Attached patch is committed. Will be available in the next 6.x-2.x-dev release.
Comment #4
sutharsan commented