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#1230 [Ref] Rationalise dedupe code loop. #15184

Merged
merged 1 commit into from
Oct 16, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Minor code cleanup

Before

Well tested function behaves as expected

After

Well tested function behaves as expected, but it also makes more sense

Technical Details

We have a function 'dedupePair' which is intended to act on a specific pair
and a loop function which iterates them.

The 'pair actions' and the 'looping actions' are currently jumbled together.

This moves the 'pair actions' to the dedupePair function
and keeps the 'looping actions' in the parent looping function.

Athough I left it out of scope for this PR the api that calls this
function should only call the 'dedupePair' function not the multiple
pair wrapper

Comments

@civibot
Copy link

civibot bot commented Sep 1, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton
Copy link
Contributor Author

@pfigel now you've done the important ones... this is just code tidy up but would be good to merge

@eileenmcnaughton eileenmcnaughton changed the title [Ref] Rationalise dedupe code loop. dev/core#1230 [Ref] Rationalise dedupe code loop. Sep 4, 2019
@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy if you are still reviewing in this area maybe you could look at this one - no worries if not it's just a minor tidy up

@@ -873,16 +873,17 @@ public static function merge($dupePairs = [], $cacheParams = [], $mode = 'safe',
unset($dupePairs[$index]);
continue;
}
CRM_Utils_Hook::merge('flip', $dupes, $dupes['dstID'], $dupes['srcID']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines relate to a single pair - so I moved them into the single pair function

// return error
return FALSE;
if (($result = self::dedupePair($dupes, $mode, $checkPermissions, $cacheKeyString)) == FALSE) {
unset($dupePairs[$index]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These relate to managing the loop - so I moved them OUT of the single pair function

@demeritcowboy
Copy link
Contributor

Sure - looking...

@demeritcowboy
Copy link
Contributor

demeritcowboy commented Sep 7, 2019

It's not really my main area and I've never looked at this block of code so it took me a bit to get into it but I was able to do some review.

  • General standards
    • [r-explain] PASS
    • [r-user] PASS
    • [r-doc] PASS
    • [r-run] PASS
      • Did a couple simple batch merge tests (which seems to be where this code is used). Results before seemed same as after.
  • Developer standards
    • [r-tech] PASS
    • [r-code] Undecided
      • In the original, it would exit the task completely at line 882. Now it just unsets something at line 877 and continues. Is the change intended? I couldn't think where this would come up.
      • Also, line 876 in the new file is a loose == instead of strict ===.
      • Since I'm out of my area on this I'll just mention it and defer - I don't see dedupePair() used in core outside of this class, but if it's used or subclassed somewhere where I'm not seeing it, then the signature change is a change (as opposed to a deprecation).
    • [r-maint] N/A
    • [r-test] PASS

We have a function 'dedupePair' which is intended to act on a specific pair
and a loop function which iterates them.

The 'pair actions' and the 'looping actions' are currently jumbled together.

This moves the 'pair actions' to the dedupePair function
and keeps the 'looping actions' in the parent looping function.

Athough I left it out of scope for this PR the api that calls this
function should only call the 'dedupePair' function not the multiple
pair wrapper
@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy I fixed the non strict comparison - strict is better practice.

WRT the other - I really can't think of when it would be hit - it seems to be a check for something that should never be true. However, the 2 most valid behaviours seem to me to be 'skip this pair & continue' or throw an exception.

In the 2 places this function is called from the batch merge expects a returned array & will get kinda weirded out if it doesn't get one. The api does cope with the 'FALSE' but would also cope with an exception. I think the handling might validation in the wrong place for the api call (any opinions @pfigel @JKingsnorth ?)

@mattwire
Copy link
Contributor

@pfigel @bjendres @JKingsnorth Please can one of you comment on the final comment from @eileenmcnaughton and confirm if the issues identified by @demeritcowboy could be an issue?

@seamuslee001
Copy link
Contributor

I think the change to unsetting makes sense in my opinion. i think it feels more correct to keep trying to go around the loop if we hit any issues

@seamuslee001 seamuslee001 added the merge ready PR will be merged after a few days if there are no objections label Oct 14, 2019
@seamuslee001
Copy link
Contributor

Added the merge ready flag to give others any chance to comment but plan to merge in a couple of days time

@eileenmcnaughton
Copy link
Contributor Author

Merging per @seamuslee001 'in a couple of days time' comment

@eileenmcnaughton eileenmcnaughton merged commit 4cef1bb into civicrm:master Oct 16, 2019
@seamuslee001 seamuslee001 deleted the dedupe9 branch October 16, 2019 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections sig:code maintenance readability testability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants