Skip to content

Campaign Emails Retrieval takes too much time #10701

@BeastMasterGrinder

Description

@BeastMasterGrinder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CampaignsIssues & PRs related to all things regarding campaignsArea: Emails:CampaignsIssues & PRs related to email campaignsPriority:ImportantIssues & PRs that are important; broken functions, errors - there are workaroundsSeverity: ModerateKey function failed, but no or little impactType: BugBugs within the core SuiteCRM codebase

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions