mirror of https://github.com/zulip/zulip.git
NarrowBuilder: Directly use denormalized 'recipient_id' of streams.
'recipient_id' was is now directly accessible and we can now use it instead of doing an extra query to Recipient model.
This commit is contained in:
parent
61d0417e75
commit
94839c9492
|
@ -29,7 +29,7 @@ from zerver.lib.message import (
|
||||||
from zerver.lib.narrow import build_narrow_filter, is_web_public_compatible
|
from zerver.lib.narrow import build_narrow_filter, is_web_public_compatible
|
||||||
from zerver.lib.request import JsonableError
|
from zerver.lib.request import JsonableError
|
||||||
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
|
from 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_queryset
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.lib.test_helpers import POSTRequestMock, get_user_messages, queries_captured
|
from zerver.lib.test_helpers import POSTRequestMock, get_user_messages, queries_captured
|
||||||
from zerver.lib.topic import MATCH_TOPIC, TOPIC_NAME
|
from zerver.lib.topic import MATCH_TOPIC, TOPIC_NAME
|
||||||
|
@ -41,8 +41,6 @@ from zerver.models import (
|
||||||
Attachment,
|
Attachment,
|
||||||
Message,
|
Message,
|
||||||
Realm,
|
Realm,
|
||||||
Recipient,
|
|
||||||
Stream,
|
|
||||||
Subscription,
|
Subscription,
|
||||||
UserMessage,
|
UserMessage,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
|
@ -1108,11 +1106,8 @@ class GetOldMessagesTest(ZulipTestCase):
|
||||||
query_ids['othello_id'] = othello_user.id
|
query_ids['othello_id'] = othello_user.id
|
||||||
query_ids['hamlet_recipient'] = hamlet_user.recipient_id
|
query_ids['hamlet_recipient'] = hamlet_user.recipient_id
|
||||||
query_ids['othello_recipient'] = othello_user.recipient_id
|
query_ids['othello_recipient'] = othello_user.recipient_id
|
||||||
recipients = Recipient.objects.filter(
|
recipients = get_public_streams_queryset(hamlet_user.realm).values_list("recipient_id", flat=True).order_by('id')
|
||||||
type=Recipient.STREAM,
|
query_ids['public_streams_recipents'] = ", ".join(str(r) for r in recipients)
|
||||||
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)
|
|
||||||
return query_ids
|
return query_ids
|
||||||
|
|
||||||
def test_content_types(self) -> None:
|
def test_content_types(self) -> None:
|
||||||
|
|
|
@ -268,10 +268,7 @@ class NarrowBuilder:
|
||||||
if operand == 'public':
|
if operand == 'public':
|
||||||
# Get all both subscribed and non subscribed public streams
|
# Get all both subscribed and non subscribed public streams
|
||||||
# but exclude any private subscribed streams.
|
# but exclude any private subscribed streams.
|
||||||
public_streams_queryset = get_public_streams_queryset(self.user_profile.realm)
|
recipient_ids = get_public_streams_queryset(self.user_realm).values_list("recipient_id", flat=True).order_by('id')
|
||||||
recipient_ids = Recipient.objects.filter(
|
|
||||||
type=Recipient.STREAM,
|
|
||||||
type_id__in=public_streams_queryset).values_list('id', flat=True).order_by('id')
|
|
||||||
cond = column("recipient_id").in_(recipient_ids)
|
cond = column("recipient_id").in_(recipient_ids)
|
||||||
return query.where(maybe_negate(cond))
|
return query.where(maybe_negate(cond))
|
||||||
raise BadNarrowOperator('unknown streams operand ' + operand)
|
raise BadNarrowOperator('unknown streams operand ' + operand)
|
||||||
|
|
Loading…
Reference in New Issue