Skip to content

Commit e4ad3ea

Browse files
committed
Squash the new stats tables more often
1 parent 6ca45f7 commit e4ad3ea

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

ureport/polls/tasks.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,15 @@ def recheck_poll_flow_data(org_id=None):
333333

334334
@app.task(name="polls.polls_stats_squash")
335335
def polls_stats_squash():
336-
from ureport.stats.models import PollEngagementDailyCount, PollStats, PollStatsCounter
336+
from ureport.stats.models import PollStats
337337

338338
r = get_valkey_connection()
339-
key = "squash_stats_lock"
339+
key = "squash_polls_stats_lock"
340340

341341
lock_timeout = 60 * 60 * 2
342342

343343
if r.get(key):
344-
logger.info("Skipping squashing stats as it is still running")
344+
logger.info("Skipping polls app squashing stats as it is still running")
345345
else:
346346
with r.lock(key, timeout=lock_timeout):
347347
PollStats.squash()
348-
PollStatsCounter.squash()
349-
PollEngagementDailyCount.squash()

ureport/polls/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,10 @@ def verify_counts():
23152315
)
23162316

23172317
activities = (
2318-
ContactActivity.objects.filter(org=self.nigeria).values("date").annotate(count__sum=Count("id")).order_by("date")
2318+
ContactActivity.objects.filter(org=self.nigeria)
2319+
.values("date")
2320+
.annotate(count__sum=Count("id"))
2321+
.order_by("date")
23192322
)
23202323
self.assertEqual(12, activity_counts.count())
23212324
self.assertEqual(12, activities.count())

ureport/settings_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,12 @@
11011101
"relative": True,
11021102
"options": {"queue": "slow"},
11031103
},
1104+
"stats_counts_squash": {
1105+
"task": "stats.stats_counts_squash",
1106+
"schedule": timedelta(minutes=5),
1107+
"relative": True,
1108+
"options": {"queue": "slow"},
1109+
},
11041110
"stats_activities_squash": {
11051111
"task": "stats.squash_contact_activities_counts",
11061112
"schedule": timedelta(minutes=15),

ureport/stats/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ def _log_stats_comparison(cls, model_name, old_stats_dict, new_stats_dict, segme
10531053

10541054

10551055
class PollStatsCounter(BaseScopedCount):
1056-
squash_max_distinct = 20000
1056+
squash_max_distinct = 100000
10571057
squash_over = ("org_id", "flow_result_id", "flow_result_category_id", "scope")
10581058

10591059
org = models.ForeignKey(Org, on_delete=models.PROTECT, related_name="poll_stats_segments")
@@ -1075,7 +1075,7 @@ class Meta:
10751075

10761076

10771077
class PollEngagementDailyCount(BaseDailyCount):
1078-
squash_max_distinct = 10000
1078+
squash_max_distinct = 100000
10791079
squash_over = ("org_id", "flow_result_id", "is_responded", "scope", "day")
10801080

10811081
org = models.ForeignKey(Org, on_delete=models.PROTECT, related_name="poll_engagement_stats")

ureport/stats/tasks.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,20 @@ def rebuild_contacts_activities_counts():
112112
logger.info(
113113
f"Task: rebuild_contacts_activities_counts finished recalculating contact activity and refreshing contacts activities engagement stats for org {org.id} in {time.time() - start_rebuild}s"
114114
)
115+
116+
117+
@app.task(name="stats.stats_counts_squash")
118+
def stats_counts_squash():
119+
from ureport.stats.models import PollEngagementDailyCount, PollStatsCounter
120+
121+
r = get_valkey_connection()
122+
key = "squash_stats_counts_lock"
123+
124+
lock_timeout = 60 * 60 * 2
125+
126+
if r.get(key):
127+
logger.info("Skipping stats app squashing stats as it is still running")
128+
else:
129+
with r.lock(key, timeout=lock_timeout):
130+
PollStatsCounter.squash()
131+
PollEngagementDailyCount.squash()

0 commit comments

Comments
 (0)