From d035857fe3eed2c935a3ec4a2a40bb9ae9462191 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 10 Jun 2020 14:30:36 +1200 Subject: [PATCH] Dedupe performance - hard-remove financial_item from list of dymnamic refs to contact tablge --- CRM/Core/DAO.php | 1 - CRM/Dedupe/MergeHandler.php | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index c6afeafc7a..871a3c1242 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2401,7 +2401,6 @@ SELECT contact_id $refsFound = []; foreach (CRM_Core_DAO_AllCoreTables::getClasses() as $daoClassName) { $links = $daoClassName::getReferenceColumns(); - $daoTableName = $daoClassName::getTableName(); foreach ($links as $refSpec) { /** @var $refSpec CRM_Core_Reference_Interface */ diff --git a/CRM/Dedupe/MergeHandler.php b/CRM/Dedupe/MergeHandler.php index 0bef4e3cc7..db454c0e70 100644 --- a/CRM/Dedupe/MergeHandler.php +++ b/CRM/Dedupe/MergeHandler.php @@ -124,6 +124,13 @@ class CRM_Dedupe_MergeHandler { if (!isset(\Civi::$statics[__CLASS__]['dynamic'])) { \Civi::$statics[__CLASS__]['dynamic'] = []; foreach (CRM_Core_DAO::getDynamicReferencesToTable('civicrm_contact') as $tableName => $field) { + if ($tableName === 'civicrm_financial_item') { + // It turns out that civicrm_financial_item does not have an index on entity_table (only as the latter + // part of a entity_id/entity_table index which probably is not adding any value over & above entity_id + // only. This means this is a slow query. The correct fix is probably to add a whitelist to + // values for entity_table in the schema. + continue; + } $sql[] = "(SELECT '$tableName' as civicrm_table, '{$field[0]}' as field_name FROM $tableName WHERE entity_table = 'civicrm_contact' LIMIT 1)"; } $sqlString = implode(' UNION ', $sql); -- 2.25.1