-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix DB crash due to timeout #1031
Conversation
Improves read performance.
* Use subquery instead of join for answers * Split main model query and view model generation * Split queries into 3 * Use ORM where possible
Fixes compatibilty with new function signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
|> Enum.map(fn c -> String.to_atom(c) end) | ||
|> Enum.zip(&1) | ||
|> Enum.into(%{})) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we put a default case here? in case of error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think it was necessary as I don't think the SQL will ever error (unless the DB server itself is down, in which case it would give the same error messages as the ones we have been having recently).
What do you think?
Our grading summary uses a long, raw SQL query to generate the JSON directly, bypassing our ORM. This causes issues when we have hundreds of thousands of answers to query.
Lots of details are glossed over in this PR as they have already been discussed internally.
Changes:
While request-response delay is only slightly improved, DB query time is improved much more significantly, as a lot of the view generation logic is done in the backend layer now. The DB only provides the bare minimum amount of data necessary to generate this view.
Tested and JSON output is of the exact same structure compared to the old query.
CAVEAT
This PR will break Avenger backlog emails. Not just because I removed the "ungraded only" functionality (which was only added in #932 and used in emails), but while compile errors are fixed to match the new function signature, it will most definitely result in a runtime error (as the email templates are not updated to reflect the new structure.
The reason I think it's fine is:
Email notifications are not used anywhere yet
I really think Add Avenger Backlog Notifications #932 is the wrong approach to generate the emails:
all_submissions_by_grader_for_index
generates a view (back then was still the JSON string), which is then converted back to a "model" usingJason.decode
, which is then further manipulated, and the final view is generated using the email template.My proposal would be to create a separate function entirely for this functionality, which would optimise everything as well. But that is out of scope of this, and will come in a follow-up PR instead.