Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

pointer: Remove fix_pre_pointer fixing logic.

Tim Abbottb77da6b8342b
diff --git a/zerver/lib/fix_unreads.py b/zerver/lib/fix_unreads.py
index f13b2811f76..2596998138c 100644
--- a/zerver/lib/fix_unreads.py
+++ b/zerver/lib/fix_unreads.py
@@ -143,97 +143,7 @@ def fix_unsubscribed(cursor: CursorObj, user_profile: UserProfile) -> None:
fix,
)
-def fix_pre_pointer(cursor: CursorObj, user_profile: UserProfile) -> None:
-
- pointer = user_profile.pointer
-
- if not pointer:
- return
-
- recipient_ids = []
-
- def find_non_muted_recipients() -> None:
- query = SQL('''
- SELECT
- zerver_subscription.recipient_id
- FROM
- zerver_subscription
- INNER JOIN zerver_recipient ON (
- zerver_recipient.id = zerver_subscription.recipient_id
- )
- WHERE (
- zerver_subscription.user_profile_id = %(user_profile_id)s AND
- zerver_recipient.type = 2 AND
- (NOT zerver_subscription.is_muted) AND
- zerver_subscription.active
- )
- ''')
- cursor.execute(query, {"user_profile_id": user_profile.id})
- rows = cursor.fetchall()
- for row in rows:
- recipient_ids.append(row[0])
- logger.info(str(recipient_ids))
-
- get_timing(
- 'find_non_muted_recipients',
- find_non_muted_recipients,
- )
-
- if not recipient_ids:
- return
-
- user_message_ids = []
-
- def find_old_ids() -> None:
- is_topic_muted = build_topic_mute_checker(cursor, user_profile)
-
- query = SQL('''
- SELECT
- zerver_usermessage.id,
- zerver_message.recipient_id,
- zerver_message.subject
- FROM
- zerver_usermessage
- INNER JOIN zerver_message ON (
- zerver_message.id = zerver_usermessage.message_id
- )
- WHERE (
- zerver_usermessage.user_profile_id = %(user_profile_id)s AND
- zerver_usermessage.message_id <= %(pointer)s AND
- (zerver_usermessage.flags & 1) = 0 AND
- zerver_message.recipient_id in %(recipient_ids)s
- )
- ''')
-
- cursor.execute(query, {
- "user_profile_id": user_profile.id,
- "pointer": pointer,
- "recipient_ids": tuple(recipient_ids),
- })
- rows = cursor.fetchall()
- for (um_id, recipient_id, topic) in rows:
- if not is_topic_muted(recipient_id, topic):
- user_message_ids.append(um_id)
- logger.info('rows found: %d', len(user_message_ids))
-
- get_timing(
- 'finding pre-pointer messages that are not muted',
- find_old_ids,
- )
-
- if not user_message_ids:
- return
-
- def fix() -> None:
- update_unread_flags(cursor, user_message_ids)
-
- get_timing(
- 'fixing unread messages for pre-pointer non-muted messages',
- fix,
- )
-
def fix(user_profile: UserProfile) -> None:
logger.info('\n---\nFixing %s:', user_profile.id)
with connection.cursor() as cursor:
fix_unsubscribed(cursor, user_profile)
- fix_pre_pointer(cursor, user_profile)
diff --git a/zerver/tests/test_unread.py b/zerver/tests/test_unread.py
index 2c66ed57546..bc1c49d51e1 100644
--- a/zerver/tests/test_unread.py
+++ b/zerver/tests/test_unread.py
@@ -4,7 +4,7 @@ from unittest import mock
import ujson
from django.db import connection
-from zerver.lib.fix_unreads import fix, fix_pre_pointer, fix_unsubscribed
+from zerver.lib.fix_unreads import fix, fix_unsubscribed
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import get_subscription, tornado_redirected_to_list
from zerver.lib.topic_mutes import add_topic_mute
@@ -403,44 +403,24 @@ class FixUnreadTests(ZulipTestCase):
um_muted_topic_id = send_message('Verona', 'muted_topic')
um_muted_stream_id = send_message('Denmark', 'whatever')
- user.pointer = self.get_last_message().id
- user.save()
-
- um_post_pointer_id = send_message('Verona', 'muted_topic')
-
self.subscribe(user, 'temporary')
um_unsubscribed_id = send_message('temporary', 'whatever')
force_unsubscribe('temporary')
- # verify data setup
+ # Verify the setup
assert_unread(um_normal_id)
assert_unread(um_muted_topic_id)
assert_unread(um_muted_stream_id)
- assert_unread(um_post_pointer_id)
- assert_unread(um_unsubscribed_id)
-
- with connection.cursor() as cursor:
- fix_pre_pointer(cursor, user)
-
- # The only message that should have been fixed is the "normal"
- # unumuted message before the pointer.
- assert_read(um_normal_id)
-
- # We don't "fix" any messages that are either muted or after the
- # pointer, because they can be legitimately unread.
- assert_unread(um_muted_topic_id)
- assert_unread(um_muted_stream_id)
- assert_unread(um_post_pointer_id)
assert_unread(um_unsubscribed_id)
# fix unsubscribed
with connection.cursor() as cursor:
fix_unsubscribed(cursor, user)
- # Most messages don't change.
+ # Muted messages don't change.
assert_unread(um_muted_topic_id)
assert_unread(um_muted_stream_id)
- assert_unread(um_post_pointer_id)
+ assert_unread(um_normal_id)
# The unsubscribed entry should change.
assert_read(um_unsubscribed_id)
@@ -448,10 +428,9 @@ class FixUnreadTests(ZulipTestCase):
# test idempotency
fix(user)
- assert_read(um_normal_id)
+ assert_unread(um_normal_id)
assert_unread(um_muted_topic_id)
assert_unread(um_muted_stream_id)
- assert_unread(um_post_pointer_id)
assert_read(um_unsubscribed_id)
class PushNotificationMarkReadFlowsTest(ZulipTestCase):