-
Notifications
You must be signed in to change notification settings - Fork 25
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
Change new count model squashing to discard zero counts #5702
Conversation
temba/flows/models.py
Outdated
VALUES (%%s, %%s, GREATEST(0, (SELECT SUM("count") FROM removed)), TRUE); | ||
SELECT * FROM ( | ||
SELECT %%s, %%s, GREATEST(0, (SELECT SUM("count") FROM removed)) AS "count", TRUE | ||
) s WHERE s."count" != 0; |
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.
using != 0
so negative totals would still be possible to support
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.
we still ignore negative values and consider them 0
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.
where?
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.
GREATEST(0, (SELECT SUM("count") FROM removed))
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.
ahh good spot.. I'm gonna remove that. If numbers are adding to something negative we've got a problem and we shouldn't just plaster over that.
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.
tho I notice that GREATEST(0, NULL) == 0
so I need to check we're not leaning on that to prevent writing NULLs....
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.
Then we can change that to COALESCE((SELECT SUM("count") FROM removed), 0)
if we need to support negative values
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.
Ok I added COALESCE tho the way the query is it's not technically needed because WHERE s."count" != 0
isn't true if count is NULL. But I think the query is easier to understand if you know count is a number.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5702 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 572 572
Lines 25925 25923 -2
=========================================
- Hits 25925 25923 -2 ☔ View full report in Codecov by Sentry. |
We're about to move node counts to the new count model and they have a special property - they all end up zero, and zero is already representable in the count model as non-existence. So let's not even store zeros.