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

Further optimize creditnote_id generation #15235

Closed
wants to merge 1 commit into from

Conversation

ejegg
Copy link
Contributor

@ejegg ejegg commented Sep 6, 2019

Overview

In case the credit notes started at an offset other than 1, avoid a potentially
very slow process of creditnote generation.
This will enable users to archive ancient contributions or start their creditnotes at a non-zero offset in case of migrating to CiviCRM without importing all existing contributions.

Before

In a DB with 48,000 contributions having a creditnote_id but
whose largest creditnote_id is 48,100, Civi makes a lookup call for
every creditnote_id between CN_48001 and CN_48101 (100 queries) when
refunding a contribution.

After

After: In a DB with 48,000 contributions having a creditnote_id but
whose largest creditnote_id is 48,100, Civi makes 3 db queries when
refunding a contribution.

Technical Details

Instead of assuming that the next available creditnote_id is equal to the count plus one, then
looping upwards until you find a free one, use db queries to actually find the maximum
creditnote_id and start from there. The loop SHOULD be unnecessary now, but I haven't
deleted it in case two donations are being refunded simultaneously.

Comments

Anything else you would like the reviewer to note

@civibot
Copy link

civibot bot commented Sep 6, 2019

(Standard links)

In case the credit notes started at an offset other than 1, avoid
making a number of getcount calls equal to the offset every time
you refund a contribution.

Before: In a DB with 48,000 contributions having a creditnote_id but
whose largest creditnote_id is 48,100, Civi makes a lookup call for
every creditnote_id between CN_48001 and CN_48101 (100 queries) when
refunding a contribution.

After: In a DB with 48,000 contributions having a creditnote_id but
whose largest creditnote_id is 48,100, Civi makes 3 db queries when
refunding a contribution.
@bjendres
Copy link
Contributor

bjendres commented Oct 9, 2019

See also lab/Core #1308

@mattwire
Copy link
Contributor

@bjendres @ejegg Is there anyone else who can verify / review this? From a code point of view it looks sensible but I'd like confirmation that it is working in a real scenario.

@eileenmcnaughton
Copy link
Contributor

Closing this out as code has been restructured & it won't apply now. We do also have a different plan for how to resolve the inefficiency on this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants