Commit 6dd717a6 authored by deb.monish's avatar deb.monish

CRM-21260: CiviMail compose UI very slow to initialize, CRM-21316: Simplify getRecipients fn

parent c865af6e
This diff is collapsed.
......@@ -147,7 +147,7 @@ class CRM_Mailing_BAO_MailingAB extends CRM_Mailing_DAO_MailingAB {
* @param CRM_Mailing_DAO_MailingAB $dao
*/
public static function distributeRecipients(CRM_Mailing_DAO_MailingAB $dao) {
CRM_Mailing_BAO_Mailing::getRecipients($dao->mailing_id_a, $dao->mailing_id_a, TRUE);
CRM_Mailing_BAO_Mailing::getRecipients($dao->mailing_id_a);
//calculate total number of random recipients for mail C from group_percentage selected
$totalCount = CRM_Mailing_BAO_Recipients::mailingSize($dao->mailing_id_a);
......
......@@ -69,10 +69,8 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
$job->scheduled_date = $params['scheduled_date'];
$job->is_test = $params['is_test'];
$job->save();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $params['mailing_id'];
if ($mailing->id && $mailing->find(TRUE)) {
$mailing->getRecipients($job->id, $params['mailing_id'], TRUE, $mailing->dedupe_email);
if ($params['mailing_id']) {
CRM_Mailing_BAO_Mailing::getRecipients($params['mailing_id']);
return $job;
}
else {
......
......@@ -266,12 +266,7 @@ class CRM_SMS_Form_Group extends CRM_Contact_Form_Task {
$this->set('mailing_id', $mailing->id);
// also compute the recipients and store them in the mailing recipients table
CRM_Mailing_BAO_Mailing::getRecipients($mailing->id,
$mailing->id,
TRUE,
FALSE,
'sms'
);
CRM_Mailing_BAO_Mailing::getRecipients($mailing->id);
$count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id);
$this->set('count', $count);
......
......@@ -114,6 +114,7 @@ class CRM_Utils_SQL_Select implements ArrayAccess {
private $mode = NULL;
private $insertInto = NULL;
private $insertVerb = 'INSERT INTO ';
private $insertIntoFields = array();
private $selects = array();
private $from;
......@@ -403,6 +404,34 @@ class CRM_Utils_SQL_Select implements ArrayAccess {
return $this;
}
/**
* Wrapper function of insertInto fn but sets insertVerb = "INSERT IGNORE INTO "
*
* @param string $table
* The name of the other table (which receives new data).
* @param array $fields
* The fields to fill in the other table (in order).
* @return CRM_Utils_SQL_Select
*/
public function insertIgnoreInto($table, $fields = array()) {
$this->insertVerb = "INSERT IGNORE INTO ";
return $this->insertInto($table, $fields);
}
/**
* Wrapper function of insertInto fn but sets insertVerb = "REPLACE INTO "
*
* @param string $table
* The name of the other table (which receives new data).
* @param array $fields
* The fields to fill in the other table (in order).
*/
public function replaceInto($table, $fields = array()) {
$this->insertVerb = "REPLACE INTO ";
return $this->insertInto($table, $fields);
}
/**
* @param array $fields
* The fields to fill in the other table (in order).
......@@ -550,10 +579,11 @@ class CRM_Utils_SQL_Select implements ArrayAccess {
public function toSQL() {
$sql = '';
if ($this->insertInto) {
$sql .= 'INSERT INTO ' . $this->insertInto . ' (';
$sql .= $this->insertVerb . $this->insertInto . ' (';
$sql .= implode(', ', $this->insertIntoFields);
$sql .= ")\n";
}
if ($this->selects) {
$sql .= 'SELECT ' . $this->distinct . implode(', ', $this->selects) . "\n";
}
......
......@@ -145,6 +145,9 @@
mids.push(dv.entity_id);
}
}
if (gids.length === 0) {
return;
}
CRM.api3('Group', 'getlist', { params: { id: { IN: gids }, options: { limit: 0 } }, extra: ["is_hidden"] } ).then(
function(glist) {
......
......@@ -270,7 +270,7 @@
else {
// Protect against races in saving and previewing by chaining create+preview.
var params = angular.extend({}, mailing, mailing.recipients, {
options: {force_rollback: 1},
id: mailing.id,
'api.Mailing.preview': {
id: '$value.id'
}
......@@ -290,11 +290,8 @@
previewRecipients: function previewRecipients(mailing, previewLimit) {
// To get list of recipients, we tentatively save the mailing and
// get the resulting recipients -- then rollback any changes.
var params = angular.extend({}, mailing, mailing.recipients, {
name: 'placeholder', // for previewing recipients on new, incomplete mailing
subject: 'placeholder', // for previewing recipients on new, incomplete mailing
options: {force_rollback: 1},
'api.mailing_job.create': 1, // note: exact match to API default
var params = angular.extend({}, mailing.recipients, {
id: mailing.id,
'api.MailingRecipients.get': {
mailing_id: '$value.id',
options: {limit: previewLimit},
......@@ -317,10 +314,7 @@
// To get list of recipients, we tentatively save the mailing and
// get the resulting recipients -- then rollback any changes.
var params = angular.extend({}, mailing, mailing.recipients, {
name: 'placeholder', // for previewing recipients on new, incomplete mailing
subject: 'placeholder', // for previewing recipients on new, incomplete mailing
options: {force_rollback: 1},
'api.mailing_job.create': 1, // note: exact match to API default
id: mailing.id,
'api.MailingRecipients.getcount': {
mailing_id: '$value.id'
}
......
......@@ -288,7 +288,6 @@ class api_v3_MailingTest extends CiviUnitTestCase {
$params['mailings']['include'] = array();
$params['mailings']['exclude'] = array();
$params['options']['force_rollback'] = 1;
$params['api.mailing_job.create'] = 1;
$params['api.MailingRecipients.get'] = array(
'mailing_id' => '$value.id',
'api.contact.getvalue' => array(
......@@ -302,12 +301,10 @@ class api_v3_MailingTest extends CiviUnitTestCase {
$maxIDs = array(
'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'),
'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
);
$create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__);
$this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records'
$this->assertDBQuery($maxIDs['job'], 'SELECT MAX(id) FROM civicrm_mailing_job'); // 'Preview should not create any mailing_job record'
$this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records'
$preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
......@@ -346,7 +343,6 @@ class api_v3_MailingTest extends CiviUnitTestCase {
$params['mailings']['include'] = array();
$params['options']['force_rollback'] = 1;
$params['dedupe_email'] = 1;
$params['api.mailing_job.create'] = 1;
$params['api.MailingRecipients.get'] = array(
'mailing_id' => '$value.id',
'api.contact.getvalue' => array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment