performance: Add get_subscriptions_for_send_message.

This new function optimizes how we fetch subscriptions
for streams.  Basically, it excludes most long-term-idle
users from the query.

With 8k users, of which all but 400 are long term idle,
this speeds up get_recipient_info from about 150ms
to 50ms.

Overall this change appears to save a factor of 2-3 in the backend
processing time for sending or editing a message in large, public
streams in chat.zulip.org (at 18K users today).
This commit is contained in:
Steve Howell
2021-05-11 11:55:49 +00:00
committed by Tim Abbott
parent c690fa1174
commit b4470ac8e1
5 changed files with 169 additions and 21 deletions

View File

@@ -1,8 +1,5 @@
from typing import Set
from django.db.models.query import QuerySet
from zerver.lib.stream_subscription import get_active_subscriptions_for_stream_id
from zerver.models import MutedTopic
@@ -26,8 +23,3 @@ class StreamTopicTarget:
"user_profile_id",
)
return {row["user_profile_id"] for row in query}
def get_active_subscriptions(self) -> QuerySet:
return get_active_subscriptions_for_stream_id(
self.stream_id, include_deactivated_users=True
)