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

Rewrite email creation function #151

Open
gravesm opened this issue Sep 27, 2019 · 0 comments
Open

Rewrite email creation function #151

gravesm opened this issue Sep 27, 2019 · 0 comments

Comments

@gravesm
Copy link

gravesm commented Sep 27, 2019

def _get_or_create_emails(pk_list):

I came across this when I was looking at some other things and this all really needs to be rewritten. It's making a ton of unnecessary SQL calls. I'm guessing this surplus of calls probably is what led to the note about closing old connections. There should be no need to close the connection here because this is absolutely happening within context of the normal request/response lifecycle. The request is probably just prone to timing out due to all the SQL calls which may be leading to stale database connections.

I tried to come up with a clear statement of what I believe to be the business rule at play here:

Given a set of records for which an email message has not been sent, create an email message for each author within that set that includes a list of their records from that set.

There also appears to be a case in which an email message has been created for an author, but before it has been sent more records get added to it. I think we should further consider under what circumstances this special case can happen and see if there's a way to get rid of it.

Starting from this rule, it should be possible to rewrite this to use at most a couple SQL calls.

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

No branches or pull requests

1 participant