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

Rework database triggers to use FlowRun.delete_from_counts #3702

Merged
merged 7 commits into from
Feb 24, 2022

Conversation

rowanseymour
Copy link
Member

@rowanseymour rowanseymour commented Feb 22, 2022

So from now on, only result category counts will be decremented when a run row is deleted. Path, exit type and start counts remain unchanged. Less trying to rewind history.

@codecov
Copy link

codecov bot commented Feb 22, 2022

Codecov Report

Merging #3702 (3116453) into main (51ab04e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #3702   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          488       489    +1     
  Lines        26167     26168    +1     
=========================================
+ Hits         26167     26168    +1     
Impacted Files Coverage Δ
temba/flows/migrations/0273_delete_from_results.py 100.00% <100.00%> (ø)
temba/flows/models.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51ab04e...3116453. Read the comment docs.

@rowanseymour rowanseymour marked this pull request as ready for review February 23, 2022 18:18
responded=bool([e for e in run["events"] if e["type"] == "msg_received"]),
)
else:
FlowRun.objects.filter(id=run_obj.id).update(**db_state)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating this to match more closely how things work in mailroom

----------------------------------------------------------------------
-- Increments or decrements our start counts for each exit type
----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION temba_update_flowstartcount() RETURNS TRIGGER AS $$
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the INSERT part into temba_flowrun_insert. We don't UPDATE start_id on flow runs except to trim starts.. at which point is more efficient to just delete the counts. We also don't need to update counts if runs are being deleted, and that might help make archiver deletes a little more efficient.

Copy link
Member

@ericnewcomer ericnewcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this matches what we talked about. I'm maybe a little spooked in that we are losing the ability to at least prove why counts don't add up (which we could still do in the archived case before), but I still feel this is the right direction.

@rowanseymour rowanseymour merged commit 09d33b8 into main Feb 24, 2022
@rowanseymour rowanseymour deleted the delete_from_counts_2 branch February 24, 2022 15:08
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

Successfully merging this pull request may close these issues.

2 participants