mirror of https://github.com/zulip/zulip.git
Have topic_is_muted take a stream_id.
This function doesn't need a full Stream object to detect whether a stream is muted, so we can save future callers from doing unnecessary DB fetches.
This commit is contained in:
parent
f55b22e937
commit
c567f105c9
|
@ -78,11 +78,11 @@ def remove_topic_mute(user_profile, stream_id, topic_name):
|
|||
)
|
||||
row.delete()
|
||||
|
||||
def topic_is_muted(user_profile, stream, topic_name):
|
||||
# type: (UserProfile, Stream, Text) -> bool
|
||||
def topic_is_muted(user_profile, stream_id, topic_name):
|
||||
# type: (UserProfile, int, Text) -> bool
|
||||
is_muted = MutedTopic.objects.filter(
|
||||
user_profile=user_profile,
|
||||
stream_id=stream.id,
|
||||
stream_id=stream_id,
|
||||
topic_name__iexact=topic_name,
|
||||
).exists()
|
||||
return is_muted
|
||||
|
|
|
@ -28,8 +28,8 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.assertIn([u'Verona', u'Verona3'], get_topic_mutes(user))
|
||||
|
||||
stream = get_stream(u'Verona', user.realm)
|
||||
self.assertTrue(topic_is_muted(user, stream, 'Verona3'))
|
||||
self.assertTrue(topic_is_muted(user, stream, 'verona3'))
|
||||
self.assertTrue(topic_is_muted(user, stream.id, 'Verona3'))
|
||||
self.assertTrue(topic_is_muted(user, stream.id, 'verona3'))
|
||||
|
||||
def test_remove_muted_topic(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -18,7 +18,7 @@ def mute_topic(user_profile, stream_name, topic_name):
|
|||
# type: (UserProfile, str, str) -> HttpResponse
|
||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||
|
||||
if topic_is_muted(user_profile, stream, topic_name):
|
||||
if topic_is_muted(user_profile, stream.id, topic_name):
|
||||
return json_error(_("Topic already muted"))
|
||||
|
||||
do_mute_topic(user_profile, stream, recipient, topic_name)
|
||||
|
@ -29,7 +29,7 @@ def unmute_topic(user_profile, stream_name, topic_name):
|
|||
error = _("Topic is not there in the muted_topics list")
|
||||
stream = access_stream_for_unmute_topic(user_profile, stream_name, error)
|
||||
|
||||
if not topic_is_muted(user_profile, stream, topic_name):
|
||||
if not topic_is_muted(user_profile, stream.id, topic_name):
|
||||
return json_error(error)
|
||||
|
||||
do_unmute_topic(user_profile, stream, topic_name)
|
||||
|
|
Loading…
Reference in New Issue