Skip to content

Commit

Permalink
Prevent clearing results for polls with the same flow
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 18, 2024
1 parent b70a33b commit 0971680
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ureport/polls/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def clear_old_poll_results(org, since, until):
syncing_window = now - timedelta(days=365)
new_window = now - timedelta(days=14)

dupes_flow_uuid = {}

old_polls = (
Poll.objects.filter(org=org)
.exclude(poll_date__gte=syncing_window)
Expand All @@ -175,8 +177,17 @@ def clear_old_poll_results(org, since, until):
logger.info(
"Skipping clearing old results for poll #%d on org #%d as it is still syncing" % (poll.pk, org.pk)
)
elif poll.flow_uuid in dupes_flow_uuid:
logger.info(
"Skipping clearing old results for poll #%d on org #%d as it appear to be duplicated"
% (poll.pk, org.pk)
)
else:

dupes_flow_uuid.add(poll.flow_uuid)
with r.lock(key, timeout=Poll.POLL_SYNC_LOCK_TIMEOUT):
# refresh the object from the DB
poll.refresh_from_db()
try:
# one last stats rebuild for the poll
poll.rebuild_poll_results_counts()
Expand Down

0 comments on commit 0971680

Please sign in to comment.