forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5612 from nyaruka/notification_counts_v2_pt2
New notification counts part 2
- Loading branch information
Showing
5 changed files
with
64 additions
and
36 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
temba/notifications/migrations/0026_backfill_new_counts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.1.2 on 2024-11-05 16:22 | ||
|
||
from django.db import migrations, transaction | ||
|
||
|
||
def backfill_item_counts(apps, schema_editor): # pragma: no cover | ||
Org = apps.get_model("orgs", "Org") | ||
|
||
for org in Org.objects.all(): | ||
user_ids = org.notifications.values_list("user_id", flat=True).distinct() | ||
|
||
for user_id in user_ids: | ||
with transaction.atomic(): | ||
seen_count = org.notifications.filter(user_id=user_id, medium__contains="U", is_seen=True).count() | ||
unseen_count = org.notifications.filter(user_id=user_id, medium__contains="U", is_seen=False).count() | ||
|
||
org.counts.filter(scope__startswith=f"notifications:{user_id}:").delete() | ||
org.counts.create(scope=f"notifications:{user_id}:S", count=seen_count, is_squashed=True) | ||
org.counts.create(scope=f"notifications:{user_id}:U", count=unseen_count, is_squashed=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("notifications", "0025_update_triggers")] | ||
|
||
operations = [migrations.RunPython(backfill_item_counts, migrations.RunPython.noop)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters