add_new_user_history: Remove the RECENT_MESSAGES_TIMEDELTA limit.

We give the new users some messages in their feed.

Earlier, we were including upto 1000 messages which were sent
within the last 12 weeks.

For realms with low-traffic it results in very few messages
being included in the new user's feed.

This commit removes the 12 week limit.
Now, we simply include upto 1000 recent messages.
This commit is contained in:
Prakhar Pratyush 2024-11-22 16:13:15 +05:30 committed by Tim Abbott
parent 7a6159eee2
commit ded6bfd3f2
2 changed files with 0 additions and 22 deletions

View File

@ -1,7 +1,6 @@
from collections import defaultdict
from collections.abc import Iterable, Sequence
from contextlib import suppress
from datetime import timedelta
from typing import Any
from django.conf import settings
@ -71,12 +70,6 @@ from zerver.tornado.django_api import send_event_on_commit
MAX_NUM_RECENT_MESSAGES = 1000
MAX_NUM_RECENT_UNREAD_MESSAGES = 20
# We don't want to mark years-old messages as unread, since that might
# feel like Zulip is buggy, but in low-traffic or bursty-traffic
# organizations, it's reasonable for the most recent 20 messages to be
# several weeks old and still be a good place to start.
RECENT_MESSAGES_TIMEDELTA = timedelta(weeks=12)
def send_message_to_signup_notification_stream(
sender: UserProfile, realm: Realm, message: str
@ -201,13 +194,11 @@ def add_new_user_history(
]
# Start by finding recent messages matching those recipients.
cutoff_date = timezone_now() - RECENT_MESSAGES_TIMEDELTA
recent_message_ids = set(
Message.objects.filter(
# Uses index: zerver_message_realm_recipient_id
realm_id=realm.id,
recipient_id__in=recipient_ids,
date_sent__gt=cutoff_date,
)
.order_by("-id")
.values_list("id", flat=True)[0:MAX_NUM_RECENT_MESSAGES]

View File

@ -1025,24 +1025,11 @@ class LoginTest(ZulipTestCase):
reset_email_visibility_to_everyone_in_zulip_realm()
realm = get_realm("zulip")
hamlet = self.example_user("hamlet")
stream_names = [f"stream_{i}" for i in range(40)]
for stream_name in stream_names:
stream = self.make_stream(stream_name, realm=realm)
DefaultStream.objects.create(stream=stream, realm=realm)
# Make sure there's at least one recent message to be mark
# unread. This prevents a bug where this test would start
# failing the test database was generated more than
# RECENT_MESSAGES_TIMEDELTA ago.
self.subscribe(hamlet, "stream_0")
self.send_stream_message(
hamlet,
"stream_0",
topic_name="test topic",
content="test message",
)
# Clear the ContentType cache.
ContentType.objects.clear_cache()