Skip to content

Commit

Permalink
dev/core#1862 Skip cache tables during merge, rely on cache managemen…
Browse files Browse the repository at this point in the history
…t processes

We later call Contact.create on both contacts so that should manage the caches for this update 'as well as for any other update'
and solve the bug + reduce locking queries
  • Loading branch information
eileenmcnaughton committed Jul 13, 2020
1 parent 3d3b6a3 commit b253bf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public static function cidRefs() {
}

$contactReferences = $coreReferences = CRM_Core_DAO::getReferencesToContactTable();
foreach (['civicrm_group_contact_cache', 'civicrm_acl_cache', 'civicrm_acl_contact_cache'] as $tableName) {
// Don't merge cache tables. These should be otherwise cleared at some point in the dedupe
// but they are prone to locking to let's not touch during the dedupe.
unset($contactReferences[$tableName], $coreReferences[$tableName]);
}

CRM_Utils_Hook::merge('cidRefs', $contactReferences);
if ($contactReferences !== $coreReferences) {
Expand Down
18 changes: 17 additions & 1 deletion tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,27 @@ public function testBatchMergeMergesGroups() {
foreach ($groupResult['values'] as $groupValues) {
$this->assertEquals($contactID, $groupValues['contact_id']);
$this->assertEquals('Added', $groupValues['status']);
$this->assertTrue(in_array($groupValues['group_id'], $expectedGroups));
$this->assertContains($groupValues['group_id'], $expectedGroups);

}
}

/**
* Test that we handle cache entries without clashes.
*/
public function testMergeCaches() {
$contactID = $this->individualCreate();
$contact2ID = $this->individualCreate();
$groupID = $this->groupCreate();
$this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID]);
$this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contact2ID]);
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_group_contact_cache(group_id, contact_id) VALUES
($groupID, $contactID),
($groupID, $contact2ID)
");
$this->callAPISuccess('Job', 'process_batch_merge', ['mode' => 'safe']);
}

/**
* Test the decisions made for addresses when merging.
*
Expand Down

0 comments on commit b253bf3

Please sign in to comment.