mirror of https://github.com/zulip/zulip.git
Have exclude_topic_mutes() accept a stream id.
We want to convert stream names to stream ids as close to the "edges" of our system as possible, so we let our caller do the work of finding the stream id for a stream narrow.
This commit is contained in:
parent
7b2340decd
commit
f13cb94d84
|
@ -298,6 +298,8 @@ def build_custom_checkers(by_lang):
|
|||
('zerver/lib/actions.py', 'get_stream(signups_stream, admin_realm)'),
|
||||
# Here we need get_stream to access streams you've since unsubscribed from.
|
||||
('zerver/views/messages.py', 'stream = get_stream(operand, self.user_profile.realm)'),
|
||||
# Use stream_id to exclude mutes.
|
||||
('zerver/views/messages.py', 'stream_id = get_stream(stream_name, user_profile.realm).id'),
|
||||
]),
|
||||
'description': 'Please use access_stream_by_*() to fetch Stream objects',
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from zerver.models import UserProfile
|
||||
|
||||
from typing import Any, Callable, Dict, List, Text
|
||||
from typing import Any, Callable, Dict, List, Optional, Text
|
||||
|
||||
from zerver.models import (
|
||||
bulk_get_recipients,
|
||||
|
@ -89,20 +89,16 @@ def topic_is_muted(user_profile, stream, topic_name):
|
|||
).exists()
|
||||
return is_muted
|
||||
|
||||
def exclude_topic_mutes(conditions, user_profile, stream_name):
|
||||
# type: (List[Selectable], UserProfile, Text) -> List[Selectable]
|
||||
def exclude_topic_mutes(conditions, user_profile, stream_id):
|
||||
# type: (List[Selectable], UserProfile, Optional[int]) -> List[Selectable]
|
||||
query = MutedTopic.objects.filter(
|
||||
user_profile=user_profile,
|
||||
)
|
||||
|
||||
if stream_name is not None:
|
||||
if stream_id is not None:
|
||||
# If we are narrowed to a stream, we can optimize the query
|
||||
# by not considering topic mutes outside the stream.
|
||||
try:
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
query = query.filter(stream=stream)
|
||||
except Stream.DoesNotExist:
|
||||
pass
|
||||
query = query.filter(stream_id=stream_id)
|
||||
|
||||
query = query.values(
|
||||
'recipient_id',
|
||||
|
|
|
@ -530,7 +530,18 @@ def exclude_muting_conditions(user_profile, narrow):
|
|||
conditions = []
|
||||
stream_name = get_stream_name_from_narrow(narrow)
|
||||
|
||||
if stream_name is None:
|
||||
stream_id = None
|
||||
if stream_name is not None:
|
||||
try:
|
||||
# Note that this code works around a lint rule that
|
||||
# says we should use access_stream_by_name to get the
|
||||
# stream. It is okay here, because we are only using
|
||||
# the stream id to exclude data, not to include results.
|
||||
stream_id = get_stream(stream_name, user_profile.realm).id
|
||||
except Stream.DoesNotExist:
|
||||
pass
|
||||
|
||||
if stream_id is None:
|
||||
rows = Subscription.objects.filter(
|
||||
user_profile=user_profile,
|
||||
active=True,
|
||||
|
@ -543,7 +554,7 @@ def exclude_muting_conditions(user_profile, narrow):
|
|||
condition = not_(column("recipient_id").in_(muted_recipient_ids))
|
||||
conditions.append(condition)
|
||||
|
||||
conditions = exclude_topic_mutes(conditions, user_profile, stream_name)
|
||||
conditions = exclude_topic_mutes(conditions, user_profile, stream_id)
|
||||
|
||||
return conditions
|
||||
|
||||
|
|
Loading…
Reference in New Issue