Campaign Emails Retrieval takes too much time #5333

Open
opened 2026-02-20 16:59:44 -05:00 by deekerman · 0 comments
Owner

Originally created by @BeastMasterGrinder on GitHub (Aug 5, 2025).

Issue

The problem is in SuiteCRM/public/legacy/modules/Emails/Emails.php

on line 3443 where we are running the query:

        $query = "SELECT contacts.first_name, contacts.last_name, contacts.phone_work, contacts.id, contacts.assigned_user_id contact_name_owner, 'Contacts' contact_name_mod FROM contacts, emails_beans ";
        $query .= "WHERE emails_beans.email_id='$this->id' AND emails_beans.bean_id=contacts.id AND emails_beans.bean_module = 'Contacts' AND emails_beans.deleted=0 AND contacts.deleted=0";
        if (!empty($this->parent_id) && $this->parent_type == 'Contacts') {
            $query .= " AND contacts.id= '" . $this->parent_id . "' ";
        } else {
            if (!empty($_REQUEST['record']) && !empty($_REQUEST['module']) && $_REQUEST['module'] == 'Contacts') {
                $query .= " AND contacts.id= '" . $_REQUEST['record'] . "' ";
            }
        }
        $result = $this->db->query($query, true, " Error filling in additional detail fields: ");

This works fine, however, on large campaigns for example more than 1 million where its run from EmailManDelievery.php at the later batches.

It fetches all the contacts who are sent the email. So for example in later batches where 1.3 or 2 million contacts are sent. This query will fetch all of them.

The irony is that later in this code the contacts fetched are not used except for 1 record. If we are only going to use it once then maybe we should get only 1 contact instead of millions of contacts?

This happens when we retrieve Emails Bean. Could be just for creating reference emails or anything

Possible Fix

Just get one contact.

Steps to Reproduce the Issue

1. Run a campaign with millions of Contacts as its Targets
...

Context

No response

Version

7.14, 8.2

What browser are you currently using?

Firefox

Browser Version

No response

Environment Information

MySQL 5.6, PHP 8.2

Operating System and Version

Ubuntu 20.0.4

Originally created by @BeastMasterGrinder on GitHub (Aug 5, 2025). ### Issue The problem is in SuiteCRM/public/legacy/modules/Emails/Emails.php on line **3443** where we are running the query: ```php $query = "SELECT contacts.first_name, contacts.last_name, contacts.phone_work, contacts.id, contacts.assigned_user_id contact_name_owner, 'Contacts' contact_name_mod FROM contacts, emails_beans "; $query .= "WHERE emails_beans.email_id='$this->id' AND emails_beans.bean_id=contacts.id AND emails_beans.bean_module = 'Contacts' AND emails_beans.deleted=0 AND contacts.deleted=0"; if (!empty($this->parent_id) && $this->parent_type == 'Contacts') { $query .= " AND contacts.id= '" . $this->parent_id . "' "; } else { if (!empty($_REQUEST['record']) && !empty($_REQUEST['module']) && $_REQUEST['module'] == 'Contacts') { $query .= " AND contacts.id= '" . $_REQUEST['record'] . "' "; } } $result = $this->db->query($query, true, " Error filling in additional detail fields: "); ``` This works fine, however, on large campaigns for example more than 1 million where its run from **EmailManDelievery.php** at the later batches. It fetches all the contacts who are sent the email. So for example in later batches where 1.3 or 2 million contacts are sent. This query will fetch all of them. The irony is that later in this code the contacts fetched are not used except for 1 record. If we are only going to use it once then maybe we should get only 1 contact instead of millions of contacts? This happens when we retrieve Emails Bean. Could be just for creating reference emails or anything ### Possible Fix Just get one contact. ### Steps to Reproduce the Issue ```bash 1. Run a campaign with millions of Contacts as its Targets ... ``` ### Context _No response_ ### Version 7.14, 8.2 ### What browser are you currently using? Firefox ### Browser Version _No response_ ### Environment Information MySQL 5.6, PHP 8.2 ### Operating System and Version Ubuntu 20.0.4
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#5333
No description provided.