Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

guest users should not be part of mau total #3800

Merged
merged 3 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3800.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guest users should not be part of mau total
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start with a capital please :)

6 changes: 5 additions & 1 deletion synapse/storage/monthly_active_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ def populate_monthly_active_users(self, user_id):
Args:
user_id(str): the user_id to query
"""

if self.hs.config.limit_usage_by_mau:
# Trial users and guests should not be included as part of MAU group
is_guest = yield self.is_guest(user_id)
if is_guest:
return
is_trial = yield self.is_trial_user(user_id)
if is_trial:
# we don't track trial users in the MAU table.
return

last_seen_timestamp = yield self.user_last_seen_monthly_active(user_id)
Expand Down
4 changes: 1 addition & 3 deletions tests/storage/test_client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ def test_updating_monthly_active_user_when_space(self):
self.hs.config.limit_usage_by_mau = True
self.hs.config.max_mau_value = 50
user_id = "@user:server"
yield self.store.register(user_id=user_id, token="123", password_hash=None)

active = yield self.store.user_last_seen_monthly_active(user_id)
self.assertFalse(active)

yield self.store.insert_client_ip(
user_id, "access_token", "ip", "user_agent", "device_id"
)
yield self.store.insert_client_ip(
user_id, "access_token", "ip", "user_agent", "device_id"
)
Expand Down
48 changes: 46 additions & 2 deletions tests/storage/test_monthly_active_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock

from twisted.internet import defer

from tests.unittest import HomeserverTestCase

Expand All @@ -23,7 +26,8 @@ def make_homeserver(self, reactor, clock):

hs = self.setup_test_homeserver()
self.store = hs.get_datastore()

hs.config.limit_usage_by_mau = True
hs.config.max_mau_value = 50
# Advance the clock a bit
reactor.advance(FORTY_DAYS)

Expand Down Expand Up @@ -73,7 +77,7 @@ def test_initialise_reserved_users(self):
active_count = self.store.get_monthly_active_count()
self.assertEquals(self.get_success(active_count), user_num)

# Test that regalar users are removed from the db
# Test that regular users are removed from the db
ru_count = 2
self.store.upsert_monthly_active_user("@ru1:server")
self.store.upsert_monthly_active_user("@ru2:server")
Expand Down Expand Up @@ -139,3 +143,43 @@ def test_reap_monthly_active_users(self):

count = self.store.get_monthly_active_count()
self.assertEquals(self.get_success(count), 0)

def test_populate_monthly_users_is_guest(self):
# Test that guest users are not added to mau list
user_id = "user_id"
self.store.register(
user_id=user_id, token="123", password_hash=None, make_guest=True
)
self.store.upsert_monthly_active_user = Mock()
self.store.populate_monthly_active_users(user_id)
self.pump()
self.store.upsert_monthly_active_user.assert_not_called()

def test_populate_monthly_users_should_update(self):
self.store.upsert_monthly_active_user = Mock()

self.store.is_trial_user = Mock(
return_value=defer.succeed(False)
)

self.store.user_last_seen_monthly_active = Mock(
return_value=defer.succeed(None)
)
self.store.populate_monthly_active_users('user_id')
self.pump()
self.store.upsert_monthly_active_user.assert_called_once()

def test_populate_monthly_users_should_not_update(self):
self.store.upsert_monthly_active_user = Mock()

self.store.is_trial_user = Mock(
return_value=defer.succeed(False)
)
self.store.user_last_seen_monthly_active = Mock(
return_value=defer.succeed(
self.hs.get_clock().time_msec()
)
)
self.store.populate_monthly_active_users('user_id')
self.pump()
self.store.upsert_monthly_active_user.assert_not_called()
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def setup_test_homeserver(
config.hs_disabled_message = ""
config.hs_disabled_limit_type = ""
config.max_mau_value = 50
config.mau_trial_days = 0
config.mau_limits_reserved_threepids = []
config.admin_contact = None
config.rc_messages_per_second = 10000
Expand Down