Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#5433 Add legacydedupefinder #31689

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jan 2, 2025

Overview

This adds a new extension for existing dedupe finder behaviour, allowing us to support the hook that is jammed in the middle of the dedupe finder code going forwards without being blocked by it (I have an existing PR that cuts many hours off the dedupe query but it is bending over backwards to work alongside the legacy attempts to allow integration).

Before

We know how to speed up dedupe queries #30591 but are working really hard around the legacy hook and the existing PR is having to rely on crazy methodology. The hook dupeQuery() is not one that has had much adoption, nor has the idea of writing custom improvements for the reserved queries. However, these 2 things have been long-standing blockers to improving performance

After

The new extension is enabled on install and on upgrade and there is no behaviour change unless a site admin disables it. If they choose to do so then

  1. the legacy hook & legacy reserved query wrangling will no longer be called

  2. dedupe queries will speed up once the blocked code is also merged Fix dedupe query wrangling to combine queries where 2 fields in the same table are always used together #30591

Technical Details

The code works by adding a new hook

findExistingDuplicates(array &$duplicates, array $ruleGroupIDs, ?string $tableName, bool $checkPermissions)

The hook is implemented by the new extension legacydedupefinder with a weight of -5 and by core with a weight of -20

legacydedupefinder calls stopPropagation() meaning that if it is enabled the core code will not be hit. Any custom extensions that give no specific thought to it will wind up with a weight of 0 - meaning they get called first, which feels like it would be as expected. Once finalised I will document this.

The function in the core code and in the extension is currently the same, except the core code is passing a parameter to fillTable to block legacy hooks from being called. Once this is merged the goal is to separate out & re-write the core function.

Before that I want to look at the second code path and attempt to do the same for it - the challenge is I really want to pass out apiv4 params to the function, not v3 https://lab.civicrm.org/dev/core/-/issues/5433

Comments

The extension is currently not hidden but if I don't get to where I want to before forking I will hide it so people do not disable it until the new hooks are settled in

@mattwire @colemanw

Copy link

civibot bot commented Jan 2, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Jan 2, 2025
Copy link

civibot bot commented Jan 2, 2025

The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/5433

*/
function legacydedupefinder_civicrm_config(&$config): void {
_legacydedupefinder_civix_civicrm_config($config);
\Civi::dispatcher()->addListener('hook_civicrm_findExistingDuplicates', ['\Civi\LegacyFinder\Finder', 'findExistingDuplicates'], -5);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn''t think this was still the right way - but my reading of https://docs.civicrm.org/dev/en/latest/hooks/usage/symfony/ is that unless it's a BAO class or in a very specific location then it still is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree the docs don't make it very clear. But don't think we should be doing it like this anymore.
I think the "correct" way would be to implement an interface, in this case `https://docs.civicrm.org/dev/en/latest/hooks/usage/symfony/#hookinterface would be fine in Civi/LegacyFinder/Finder.php and make sure you have scan-classes mixin enabled because it's in an extension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire I just tried & failed to switch over - see #31959

I tried (very reluctantly) renaming the class to a BAO class - as that seemed slightly less inaccurate than an apiv4 event subscriber class per

image

But no joy.

Note HookInterface doesn't seem right as it has no ability to set weight

bin/regen.sh Outdated Show resolved Hide resolved
@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton eileenmcnaughton force-pushed the finder_ext branch 3 times, most recently from f240f20 to c3a8dc5 Compare February 4, 2025 02:23
</classloader>
<civix>
<namespace>CRM/Legacydedupefinder</namespace>
<format>24.09.1</format>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton As this is going into core can we generate with latest civix please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire done - I've also made it 'hidden' for now - until I've migrated the second hook

@@ -29,6 +29,7 @@ class CRM_Upgrade_Incremental_php_FiveEightyTwo extends CRM_Upgrade_Incremental_
*/
public function upgrade_5_82_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addSimpleExtensionTask(ts('enable dedupe backward compatibility'), ['legacydedupefinder']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton I think this needs to be moved to SixZero.

=====
Overview
====

This adds a new extension for existing dedupe finder behaviour, allowing us to support the
hook that is jammed in the middle of the dedupe finder code going forwards without
being blocked by it (I have an existing PR that cuts many hours off the
dedupe query but it is bending over backwards to work alongside the legacy
attempts to allow integration).

The new extension is enabled on install and on upgrade and there is no behaviour change unless
a site admin disables it. If they choose to do so then

1) the legacy hook & legacy reserved query wrangling will no longer be called
2) dedupe queries will speed up once the blocked code is also merged
civicrm#30591
@eileenmcnaughton eileenmcnaughton merged commit 5e0868c into civicrm:master Feb 6, 2025
1 check passed
@eileenmcnaughton eileenmcnaughton deleted the finder_ext branch February 6, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants