add mau_trial_days config param.
only consider users MAU after they've been around N days. This is an alternative implementation to https://github.com/matrix-org/synapse/pull/3739 as suggested by @neilisfragile, which is much simpler as you just hold off adding users to the MAU table until they've been active for more than N days.
This commit is contained in:
@@ -41,6 +41,7 @@ class AuthTestCase(unittest.TestCase):
|
||||
self.macaroon_generator = self.hs.get_macaroon_generator()
|
||||
# MAU tests
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
self.small_number_of_users = 1
|
||||
self.large_number_of_users = 100
|
||||
|
||||
@@ -161,14 +162,14 @@ class AuthTestCase(unittest.TestCase):
|
||||
)
|
||||
# If in monthly active cohort
|
||||
self.hs.get_datastore().user_last_seen_monthly_active = Mock(
|
||||
return_value=defer.succeed(self.hs.get_clock().time_msec())
|
||||
return_value=defer.succeed((self.hs.get_clock().time_msec(), False))
|
||||
)
|
||||
self.hs.get_datastore().get_monthly_active_count = Mock(
|
||||
return_value=defer.succeed(self.hs.config.max_mau_value)
|
||||
)
|
||||
yield self.auth_handler.get_access_token_for_user_id('user_a')
|
||||
self.hs.get_datastore().user_last_seen_monthly_active = Mock(
|
||||
return_value=defer.succeed(self.hs.get_clock().time_msec())
|
||||
return_value=defer.succeed((self.hs.get_clock().time_msec(), False))
|
||||
)
|
||||
self.hs.get_datastore().get_monthly_active_count = Mock(
|
||||
return_value=defer.succeed(self.hs.config.max_mau_value)
|
||||
|
||||
@@ -54,6 +54,7 @@ class RegistrationTestCase(unittest.TestCase):
|
||||
self.handler = self.hs.get_handlers().registration_handler
|
||||
self.store = self.hs.get_datastore()
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
self.lots_of_users = 100
|
||||
self.small_number_of_users = 1
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class SyncTestCase(tests.unittest.TestCase):
|
||||
|
||||
self.hs.config.limit_usage_by_mau = True
|
||||
self.hs.config.max_mau_value = 1
|
||||
self.hs.config.mau_trial_days = 0
|
||||
|
||||
# Check that the happy case does not throw errors
|
||||
yield self.store.upsert_monthly_active_user(user_id1)
|
||||
|
||||
@@ -59,6 +59,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||
def test_disabled_monthly_active_user(self):
|
||||
self.hs.config.limit_usage_by_mau = False
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
user_id = "@user:server"
|
||||
yield self.store.insert_client_ip(
|
||||
user_id, "access_token", "ip", "user_agent", "device_id"
|
||||
@@ -70,6 +71,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||
def test_adding_monthly_active_user_when_full(self):
|
||||
self.hs.config.limit_usage_by_mau = True
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
lots_of_users = 100
|
||||
user_id = "@user:server"
|
||||
|
||||
@@ -86,6 +88,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||
def test_adding_monthly_active_user_when_space(self):
|
||||
self.hs.config.limit_usage_by_mau = True
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
user_id = "@user:server"
|
||||
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||
self.assertFalse(active)
|
||||
@@ -100,6 +103,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||
def test_updating_monthly_active_user_when_space(self):
|
||||
self.hs.config.limit_usage_by_mau = True
|
||||
self.hs.config.max_mau_value = 50
|
||||
self.hs.config.mau_trial_days = 0
|
||||
user_id = "@user:server"
|
||||
|
||||
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||
|
||||
@@ -30,6 +30,7 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.hs = yield setup_test_homeserver(self.addCleanup)
|
||||
self.store = self.hs.get_datastore()
|
||||
self.hs.config.mau_trial_days = 0
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_initialise_reserved_users(self):
|
||||
@@ -105,13 +106,13 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||
user_id3 = "@user3:server"
|
||||
|
||||
result = yield self.store.user_last_seen_monthly_active(user_id1)
|
||||
self.assertFalse(result == 0)
|
||||
self.assertFalse(result)
|
||||
yield self.store.upsert_monthly_active_user(user_id1)
|
||||
yield self.store.upsert_monthly_active_user(user_id2)
|
||||
result = yield self.store.user_last_seen_monthly_active(user_id1)
|
||||
self.assertTrue(result > 0)
|
||||
self.assertTrue(result[0] > 0)
|
||||
result = yield self.store.user_last_seen_monthly_active(user_id3)
|
||||
self.assertFalse(result == 0)
|
||||
self.assertFalse(result)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_reap_monthly_active_users(self):
|
||||
|
||||
Reference in New Issue
Block a user