Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hybrid properties were the root cause of performance issues with various queries we were trying to run on model receipts. Now we return an SQL aggregate function instead, allowing you to build similar queries without the massive performance hit. This change uses the attendee receipt discrepancies and nonzero balance pages as a proof of concept -- if these become useable once on prod, then we can apply this change to related currently-unusable pages.
One important thing to note is that you should NOT ever use the new _sql aggregate functions from two different tables in one query -- this either creates a cartesian join or, if you specify joins, repeats the rows from earlier tables in the join and screws up calculations (e.g., doubling the item total). You can see how we handle needing aggregates from two different tables in the attendees_nonzero_balance page handler, where we create a subquery for the ReceiptItems table. This appears to work well alongside normal aggregate functions/outer joins for ReceiptTransactions.
For more information, see https://stackoverflow.com/questions/12484975/sqlalchemy-using-func-with-outerjoin-on-multiple-tables and https://blog.miguelgrinberg.com/post/nested-queries-with-sqlalchemy-orm