mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-17 23:42:33 +01:00
Revert "change monthly_active_users table to be a single column"
This reverts commit ec716a35b2
.
This commit is contained in:
parent
ec716a35b2
commit
165e067033
3 changed files with 13 additions and 7 deletions
|
@ -38,18 +38,22 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
||||||
return count
|
return count
|
||||||
return self.runInteraction("count_users", _count_users)
|
return self.runInteraction("count_users", _count_users)
|
||||||
|
|
||||||
def insert_monthly_active_user(self, user_id):
|
def upsert_monthly_active_user(self, user_id):
|
||||||
"""
|
"""
|
||||||
Updates or inserts monthly active user member
|
Updates or inserts monthly active user member
|
||||||
Arguments:
|
Arguments:
|
||||||
user_id (str): user to add/update
|
user_id (str): user to add/update
|
||||||
"""
|
"""
|
||||||
return self._simple_insert(
|
return self._simple_upsert(
|
||||||
desc="upsert_monthly_active_user",
|
desc="upsert_monthly_active_user",
|
||||||
table="monthly_active_users",
|
table="monthly_active_users",
|
||||||
values={
|
keyvalues={
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
},
|
},
|
||||||
|
values={
|
||||||
|
"timestamp": int(self._clock.time_msec()),
|
||||||
|
},
|
||||||
|
lock=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
|
|
||||||
-- a table of monthly active users, for use where blocking based on mau limits
|
-- a table of monthly active users, for use where blocking based on mau limits
|
||||||
CREATE TABLE monthly_active_users (
|
CREATE TABLE monthly_active_users (
|
||||||
user_id TEXT NOT NULL
|
user_id TEXT NOT NULL,
|
||||||
|
timestamp BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX monthly_active_users_users ON monthly_active_users(user_id);
|
CREATE UNIQUE INDEX monthly_active_users_users ON monthly_active_users(user_id);
|
||||||
|
CREATE INDEX monthly_active_users_time_stamp ON monthly_active_users(timestamp);
|
||||||
|
|
|
@ -22,7 +22,7 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||||
count = yield self.mau.get_monthly_active_count()
|
count = yield self.mau.get_monthly_active_count()
|
||||||
self.assertEqual(0, count)
|
self.assertEqual(0, count)
|
||||||
|
|
||||||
yield self.mau.insert_monthly_active_user("@user:server")
|
yield self.mau.upsert_monthly_active_user("@user:server")
|
||||||
count = yield self.mau.get_monthly_active_count()
|
count = yield self.mau.get_monthly_active_count()
|
||||||
|
|
||||||
self.assertEqual(1, count)
|
self.assertEqual(1, count)
|
||||||
|
@ -34,8 +34,8 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
||||||
user_id3 = "@user3:server"
|
user_id3 = "@user3:server"
|
||||||
result = yield self.mau.is_user_monthly_active(user_id1)
|
result = yield self.mau.is_user_monthly_active(user_id1)
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
yield self.mau.insert_monthly_active_user(user_id1)
|
yield self.mau.upsert_monthly_active_user(user_id1)
|
||||||
yield self.mau.insert_monthly_active_user(user_id2)
|
yield self.mau.upsert_monthly_active_user(user_id2)
|
||||||
result = yield self.mau.is_user_monthly_active(user_id1)
|
result = yield self.mau.is_user_monthly_active(user_id1)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
result = yield self.mau.is_user_monthly_active(user_id3)
|
result = yield self.mau.is_user_monthly_active(user_id3)
|
||||||
|
|
Loading…
Reference in a new issue