mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
stream: Add subscriber_count field.
Fixes #34246. Add subscriber_count field to Stream model to track number of non-deactivated users subscribed to the channel.
This commit is contained in:
@@ -47,7 +47,10 @@ from zerver.lib.mobile_auth_otp import (
|
||||
)
|
||||
from zerver.lib.name_restrictions import is_disposable_domain
|
||||
from zerver.lib.send_email import EmailNotDeliveredError, FromAddress, send_future_email
|
||||
from zerver.lib.stream_subscription import get_stream_subscriptions_for_user
|
||||
from zerver.lib.stream_subscription import (
|
||||
get_stream_subscriptions_for_user,
|
||||
get_user_subscribed_streams,
|
||||
)
|
||||
from zerver.lib.streams import create_stream_if_needed
|
||||
from zerver.lib.subdomains import is_root_domain_available
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
@@ -1029,7 +1032,7 @@ class LoginTest(ZulipTestCase):
|
||||
# to sending messages, such as getting the welcome bot, looking up
|
||||
# the alert words for a realm, etc.
|
||||
with (
|
||||
self.assert_database_query_count(95),
|
||||
self.assert_database_query_count(96),
|
||||
self.assert_memcached_count(18),
|
||||
self.captureOnCommitCallbacks(execute=True),
|
||||
):
|
||||
@@ -2807,6 +2810,59 @@ class UserSignUpTest(ZulipTestCase):
|
||||
result = self.submit_reg_form_for_user(email, password, default_stream_groups=["group 1"])
|
||||
self.check_user_subscribed_only_to_streams("newguy", default_streams | set(group1_streams))
|
||||
|
||||
def test_signup_stream_subscriber_count(self) -> None:
|
||||
"""
|
||||
Verify that signing up successfully increments subscriber_count by 1
|
||||
for that new user subscribed streams.
|
||||
"""
|
||||
email = "newguy@zulip.com"
|
||||
password = "newpassword"
|
||||
realm = get_realm("zulip")
|
||||
|
||||
all_streams_subscriber_count = self.build_streams_subscriber_count(
|
||||
streams=Stream.objects.all()
|
||||
)
|
||||
|
||||
result = self.verify_signup(email=email, password=password, realm=realm)
|
||||
assert isinstance(result, UserProfile)
|
||||
|
||||
user_profile = result
|
||||
user_stream_ids = {stream.id for stream in get_user_subscribed_streams(user_profile)}
|
||||
|
||||
streams_subscriber_counts_before = {
|
||||
stream_id: count
|
||||
for stream_id, count in all_streams_subscriber_count.items()
|
||||
if stream_id in user_stream_ids
|
||||
}
|
||||
|
||||
other_streams_subscriber_counts_before = {
|
||||
stream_id: count
|
||||
for stream_id, count in all_streams_subscriber_count.items()
|
||||
if stream_id not in user_stream_ids
|
||||
}
|
||||
|
||||
# DB-refresh streams.
|
||||
streams_subscriber_counts_after = self.fetch_streams_subscriber_count(user_stream_ids)
|
||||
|
||||
# DB-refresh other_streams.
|
||||
other_streams_subscriber_counts_after = self.fetch_other_streams_subscriber_count(
|
||||
user_stream_ids
|
||||
)
|
||||
|
||||
# Signing up a user should result in subscriber_count + 1
|
||||
self.assert_stream_subscriber_count(
|
||||
streams_subscriber_counts_before,
|
||||
streams_subscriber_counts_after,
|
||||
expected_difference=1,
|
||||
)
|
||||
|
||||
# Make sure other streams are not affected upon signup.
|
||||
self.assert_stream_subscriber_count(
|
||||
other_streams_subscriber_counts_before,
|
||||
other_streams_subscriber_counts_after,
|
||||
expected_difference=0,
|
||||
)
|
||||
|
||||
def test_signup_two_confirmation_links(self) -> None:
|
||||
email = self.nonreg_email("newguy")
|
||||
password = "newpassword"
|
||||
|
Reference in New Issue
Block a user