Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
NarrowBuilder: Directly use denormalized 'recipient_id' of streams.
Aman Agrawal94839c9492c4
diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex ab065dc47c5..4dcdb66ffcf 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -29,7 +29,7 @@ from zerver.lib.message import (from zerver.lib.narrow import build_narrow_filter, is_web_public_compatiblefrom zerver.lib.request import JsonableErrorfrom zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection-from zerver.lib.streams import create_streams_if_needed+from zerver.lib.streams import create_streams_if_needed, get_public_streams_querysetfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import POSTRequestMock, get_user_messages, queries_capturedfrom zerver.lib.topic import MATCH_TOPIC, TOPIC_NAME@@ -41,8 +41,6 @@ from zerver.models import (Attachment,Message,Realm,- Recipient,- Stream,Subscription,UserMessage,UserProfile,@@ -1108,11 +1106,8 @@ class GetOldMessagesTest(ZulipTestCase):query_ids['othello_id'] = othello_user.idquery_ids['hamlet_recipient'] = hamlet_user.recipient_idquery_ids['othello_recipient'] = othello_user.recipient_id- recipients = Recipient.objects.filter(- type=Recipient.STREAM,- type_id__in=Stream.objects.filter(realm=hamlet_user.realm, invite_only=False),- ).values('id').order_by('id')- query_ids['public_streams_recipents'] = ", ".join(str(r['id']) for r in recipients)+ recipients = get_public_streams_queryset(hamlet_user.realm).values_list("recipient_id", flat=True).order_by('id')+ query_ids['public_streams_recipents'] = ", ".join(str(r) for r in recipients)return query_idsdef test_content_types(self) -> None:diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.pyindex 03f258dddf5..7b19ee15269 100644--- a/zerver/views/message_fetch.py+++ b/zerver/views/message_fetch.py@@ -268,10 +268,7 @@ class NarrowBuilder:if operand == 'public':# Get all both subscribed and non subscribed public streams# but exclude any private subscribed streams.- public_streams_queryset = get_public_streams_queryset(self.user_profile.realm)- recipient_ids = Recipient.objects.filter(- type=Recipient.STREAM,- type_id__in=public_streams_queryset).values_list('id', flat=True).order_by('id')+ recipient_ids = get_public_streams_queryset(self.user_realm).values_list("recipient_id", flat=True).order_by('id')cond = column("recipient_id").in_(recipient_ids)return query.where(maybe_negate(cond))raise BadNarrowOperator('unknown streams operand ' + operand)