mirror of https://github.com/zulip/zulip.git
messages: Eliminate redundant realm fetch in has_message_access.
Accessing .realm will cause a fetch query from the database if the attribute hasn't been fetched already earlier in the codepath. That's completely redundant if we're just comparing realms, and we should only access .realm_id attribute. This seems to eliminate a query in some codepaths, which is nice in this performance-sensitive function.
This commit is contained in:
parent
a7fd994cbd
commit
89d1f1f385
|
@ -826,7 +826,7 @@ def has_message_access(
|
||||||
else:
|
else:
|
||||||
assert stream.recipient_id == message.recipient_id
|
assert stream.recipient_id == message.recipient_id
|
||||||
|
|
||||||
if stream.realm != user_profile.realm:
|
if stream.realm_id != user_profile.realm_id:
|
||||||
# You can't access public stream messages in other realms
|
# You can't access public stream messages in other realms
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -1412,7 +1412,7 @@ class EditMessageTest(EditMessageTestCase):
|
||||||
set_topic_mutes(desdemona, muted_topics)
|
set_topic_mutes(desdemona, muted_topics)
|
||||||
set_topic_mutes(cordelia, muted_topics)
|
set_topic_mutes(cordelia, muted_topics)
|
||||||
|
|
||||||
with self.assert_database_query_count(31):
|
with self.assert_database_query_count(30):
|
||||||
check_update_message(
|
check_update_message(
|
||||||
user_profile=desdemona,
|
user_profile=desdemona,
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
|
@ -1443,7 +1443,7 @@ class EditMessageTest(EditMessageTestCase):
|
||||||
set_topic_mutes(desdemona, muted_topics)
|
set_topic_mutes(desdemona, muted_topics)
|
||||||
set_topic_mutes(cordelia, muted_topics)
|
set_topic_mutes(cordelia, muted_topics)
|
||||||
|
|
||||||
with self.assert_database_query_count(33):
|
with self.assert_database_query_count(32):
|
||||||
check_update_message(
|
check_update_message(
|
||||||
user_profile=desdemona,
|
user_profile=desdemona,
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
|
@ -1476,7 +1476,7 @@ class EditMessageTest(EditMessageTestCase):
|
||||||
set_topic_mutes(desdemona, muted_topics)
|
set_topic_mutes(desdemona, muted_topics)
|
||||||
set_topic_mutes(cordelia, muted_topics)
|
set_topic_mutes(cordelia, muted_topics)
|
||||||
|
|
||||||
with self.assert_database_query_count(31):
|
with self.assert_database_query_count(30):
|
||||||
check_update_message(
|
check_update_message(
|
||||||
user_profile=desdemona,
|
user_profile=desdemona,
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
|
@ -1499,7 +1499,7 @@ class EditMessageTest(EditMessageTestCase):
|
||||||
second_message_id = self.send_stream_message(
|
second_message_id = self.send_stream_message(
|
||||||
hamlet, stream_name, topic_name="changed topic name", content="Second message"
|
hamlet, stream_name, topic_name="changed topic name", content="Second message"
|
||||||
)
|
)
|
||||||
with self.assert_database_query_count(25):
|
with self.assert_database_query_count(24):
|
||||||
check_update_message(
|
check_update_message(
|
||||||
user_profile=desdemona,
|
user_profile=desdemona,
|
||||||
message_id=second_message_id,
|
message_id=second_message_id,
|
||||||
|
|
Loading…
Reference in New Issue