mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-18 07:52:56 +01:00
rename _user_last_seen_monthly_active
This commit is contained in:
parent
c1f9dec92a
commit
885ea9c602
4 changed files with 19 additions and 18 deletions
|
@ -789,7 +789,7 @@ class Auth(object):
|
||||||
if self.hs.config.limit_usage_by_mau is True:
|
if self.hs.config.limit_usage_by_mau is True:
|
||||||
# If the user is already part of the MAU cohort
|
# If the user is already part of the MAU cohort
|
||||||
if user_id:
|
if user_id:
|
||||||
timestamp = yield self.store._user_last_seen_monthly_active(user_id)
|
timestamp = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
if timestamp:
|
if timestamp:
|
||||||
return
|
return
|
||||||
# Else if there is no room in the MAU bucket, bail
|
# Else if there is no room in the MAU bucket, bail
|
||||||
|
|
|
@ -113,7 +113,7 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
||||||
# is racy.
|
# is racy.
|
||||||
# Have resolved to invalidate the whole cache for now and do
|
# Have resolved to invalidate the whole cache for now and do
|
||||||
# something about it if and when the perf becomes significant
|
# something about it if and when the perf becomes significant
|
||||||
self._user_last_seen_monthly_active.invalidate_all()
|
self.user_last_seen_monthly_active.invalidate_all()
|
||||||
self.get_monthly_active_count.invalidate_all()
|
self.get_monthly_active_count.invalidate_all()
|
||||||
|
|
||||||
@cached(num_args=0)
|
@cached(num_args=0)
|
||||||
|
@ -152,11 +152,11 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
||||||
lock=False,
|
lock=False,
|
||||||
)
|
)
|
||||||
if is_insert:
|
if is_insert:
|
||||||
self._user_last_seen_monthly_active.invalidate((user_id,))
|
self.user_last_seen_monthly_active.invalidate((user_id,))
|
||||||
self.get_monthly_active_count.invalidate(())
|
self.get_monthly_active_count.invalidate(())
|
||||||
|
|
||||||
@cached(num_args=1)
|
@cached(num_args=1)
|
||||||
def _user_last_seen_monthly_active(self, user_id):
|
def user_last_seen_monthly_active(self, user_id):
|
||||||
"""
|
"""
|
||||||
Checks if a given user is part of the monthly active user group
|
Checks if a given user is part of the monthly active user group
|
||||||
Arguments:
|
Arguments:
|
||||||
|
@ -173,7 +173,7 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
||||||
},
|
},
|
||||||
retcol="timestamp",
|
retcol="timestamp",
|
||||||
allow_none=True,
|
allow_none=True,
|
||||||
desc="_user_last_seen_monthly_active",
|
desc="user_last_seen_monthly_active",
|
||||||
))
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -185,7 +185,7 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
||||||
user_id(str): the user_id to query
|
user_id(str): the user_id to query
|
||||||
"""
|
"""
|
||||||
if self.hs.config.limit_usage_by_mau:
|
if self.hs.config.limit_usage_by_mau:
|
||||||
last_seen_timestamp = yield self._user_last_seen_monthly_active(user_id)
|
last_seen_timestamp = yield self.user_last_seen_monthly_active(user_id)
|
||||||
now = self.hs.get_clock().time_msec()
|
now = self.hs.get_clock().time_msec()
|
||||||
|
|
||||||
# We want to reduce to the total number of db writes, and are happy
|
# We want to reduce to the total number of db writes, and are happy
|
||||||
|
|
|
@ -64,7 +64,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
user_id, "access_token", "ip", "user_agent", "device_id",
|
user_id, "access_token", "ip", "user_agent", "device_id",
|
||||||
)
|
)
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertFalse(active)
|
self.assertFalse(active)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -80,7 +80,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
user_id, "access_token", "ip", "user_agent", "device_id",
|
user_id, "access_token", "ip", "user_agent", "device_id",
|
||||||
)
|
)
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertFalse(active)
|
self.assertFalse(active)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -88,13 +88,13 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||||
self.hs.config.limit_usage_by_mau = True
|
self.hs.config.limit_usage_by_mau = True
|
||||||
self.hs.config.max_mau_value = 50
|
self.hs.config.max_mau_value = 50
|
||||||
user_id = "@user:server"
|
user_id = "@user:server"
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertFalse(active)
|
self.assertFalse(active)
|
||||||
|
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
user_id, "access_token", "ip", "user_agent", "device_id",
|
user_id, "access_token", "ip", "user_agent", "device_id",
|
||||||
)
|
)
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertTrue(active)
|
self.assertTrue(active)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -103,7 +103,7 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||||
self.hs.config.max_mau_value = 50
|
self.hs.config.max_mau_value = 50
|
||||||
user_id = "@user:server"
|
user_id = "@user:server"
|
||||||
|
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertFalse(active)
|
self.assertFalse(active)
|
||||||
|
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
|
@ -112,5 +112,5 @@ class ClientIpStoreTestCase(tests.unittest.TestCase):
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
user_id, "access_token", "ip", "user_agent", "device_id",
|
user_id, "access_token", "ip", "user_agent", "device_id",
|
||||||
)
|
)
|
||||||
active = yield self.store._user_last_seen_monthly_active(user_id)
|
active = yield self.store.user_last_seen_monthly_active(user_id)
|
||||||
self.assertTrue(active)
|
self.assertTrue(active)
|
||||||
|
|
|
@ -66,9 +66,9 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||||
|
|
||||||
# Test user is marked as active
|
# Test user is marked as active
|
||||||
|
|
||||||
timestamp = yield self.store._user_last_seen_monthly_active(user1)
|
timestamp = yield self.store.user_last_seen_monthly_active(user1)
|
||||||
self.assertTrue(timestamp)
|
self.assertTrue(timestamp)
|
||||||
timestamp = yield self.store._user_last_seen_monthly_active(user2)
|
timestamp = yield self.store.user_last_seen_monthly_active(user2)
|
||||||
self.assertTrue(timestamp)
|
self.assertTrue(timestamp)
|
||||||
|
|
||||||
# Test that users are never removed from the db.
|
# Test that users are never removed from the db.
|
||||||
|
@ -92,17 +92,18 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||||
self.assertEqual(1, count)
|
self.assertEqual(1, count)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test__user_last_seen_monthly_active(self):
|
def test_user_last_seen_monthly_active(self):
|
||||||
user_id1 = "@user1:server"
|
user_id1 = "@user1:server"
|
||||||
user_id2 = "@user2:server"
|
user_id2 = "@user2:server"
|
||||||
user_id3 = "@user3:server"
|
user_id3 = "@user3:server"
|
||||||
result = yield self.store._user_last_seen_monthly_active(user_id1)
|
|
||||||
|
result = yield self.store.user_last_seen_monthly_active(user_id1)
|
||||||
self.assertFalse(result == 0)
|
self.assertFalse(result == 0)
|
||||||
yield self.store.upsert_monthly_active_user(user_id1)
|
yield self.store.upsert_monthly_active_user(user_id1)
|
||||||
yield self.store.upsert_monthly_active_user(user_id2)
|
yield self.store.upsert_monthly_active_user(user_id2)
|
||||||
result = yield self.store._user_last_seen_monthly_active(user_id1)
|
result = yield self.store.user_last_seen_monthly_active(user_id1)
|
||||||
self.assertTrue(result > 0)
|
self.assertTrue(result > 0)
|
||||||
result = yield self.store._user_last_seen_monthly_active(user_id3)
|
result = yield self.store.user_last_seen_monthly_active(user_id3)
|
||||||
self.assertFalse(result == 0)
|
self.assertFalse(result == 0)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue