-
Notifications
You must be signed in to change notification settings - Fork 27
Invisible unread comments issue #4467
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f2ffb6e
Ensure we send hasMarkedAsRead request only after loading comments list
hlbmtc fb8e2a5
Backend unread pagination: prioritize threads with unread comments fo…
hlbmtc 69b600a
Added tests
hlbmtc 4079b85
Merge branch 'main' into fix/unread-comments
hlbmtc 44c2cbc
Merge branch 'main' into fix/unread-comments
hlbmtc 5b15647
Merge branch 'main' into fix/unread-comments
hlbmtc c9c8610
Fixed combination with is_focused_comment
hlbmtc 00fa864
Moved soft_delete_user and clean_user_data_delete to the separate ser…
hlbmtc c73017a
Added sync_snapshot_comments_count command
hlbmtc df7d7f8
Small fix
hlbmtc 545b4f9
Adjusted `clean_user_data_delete`
hlbmtc 43a41b0
Merge branch 'main' into fix/unread-comments
hlbmtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
comments/management/commands/sync_snapshot_comments_count.py
This file contains hidden or 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,69 @@ | ||
| from django.core.management.base import BaseCommand | ||
| from django.db.models import Count, Subquery, OuterRef | ||
| from django.db.models.functions import Coalesce | ||
|
|
||
| from comments.models import Comment | ||
| from posts.models import PostUserSnapshot | ||
|
|
||
| BATCH_SIZE = 5000 | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Sync PostUserSnapshot.comments_count to match actual comment counts at viewed_at" | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| "--dry-run", | ||
| action="store_true", | ||
| help="Only report mismatches without updating", | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| dry_run = options["dry_run"] | ||
|
|
||
| correct_count = Coalesce( | ||
| Subquery( | ||
| Comment.objects.filter( | ||
| on_post_id=OuterRef("post_id"), | ||
| is_private=False, | ||
| is_soft_deleted=False, | ||
| created_at__lte=OuterRef("viewed_at"), | ||
| ) | ||
| .order_by() | ||
| .values("on_post_id") | ||
| .annotate(cnt=Count("id")) | ||
| .values("cnt") | ||
| ), | ||
| 0, | ||
| ) | ||
|
|
||
| total = PostUserSnapshot.objects.count() | ||
| processed = 0 | ||
| updated = 0 | ||
| batch = [] | ||
|
|
||
| for pk in PostUserSnapshot.objects.values_list("pk", flat=True).iterator( | ||
| chunk_size=BATCH_SIZE | ||
| ): | ||
| batch.append(pk) | ||
| if len(batch) >= BATCH_SIZE: | ||
| if not dry_run: | ||
| updated += PostUserSnapshot.objects.filter(pk__in=batch).update( | ||
| comments_count=correct_count | ||
| ) | ||
| processed += len(batch) | ||
| batch = [] | ||
| if processed % 50000 == 0: | ||
| self.stdout.write(f" processed {processed}/{total}...") | ||
|
|
||
| if batch: | ||
| if not dry_run: | ||
| updated += PostUserSnapshot.objects.filter(pk__in=batch).update( | ||
| comments_count=correct_count | ||
| ) | ||
| processed += len(batch) | ||
|
|
||
| self.stdout.write( | ||
| f"\nDone. Total: {total}, processed: {processed}, " | ||
| f"updated: {updated}{' (dry-run)' if dry_run else ''}" | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.