mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-07 17:42:13 -04:00
Convert directory, e2e_room_keys, end_to_end_keys, monthly_active_users database to async (#8042)
This commit is contained in:
parent
f3fe6961b2
commit
7f837959ea
10 changed files with 141 additions and 120 deletions
|
@ -15,8 +15,6 @@
|
|||
import logging
|
||||
from typing import List
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.storage._base import SQLBaseStore
|
||||
from synapse.storage.database import DatabasePool, make_in_list_sql_clause
|
||||
from synapse.util.caches.descriptors import cached
|
||||
|
@ -252,16 +250,12 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
|||
"reap_monthly_active_users", _reap_users, reserved_users
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def upsert_monthly_active_user(self, user_id):
|
||||
async def upsert_monthly_active_user(self, user_id: str) -> None:
|
||||
"""Updates or inserts the user into the monthly active user table, which
|
||||
is used to track the current MAU usage of the server
|
||||
|
||||
Args:
|
||||
user_id (str): user to add/update
|
||||
|
||||
Returns:
|
||||
Deferred
|
||||
user_id: user to add/update
|
||||
"""
|
||||
# Support user never to be included in MAU stats. Note I can't easily call this
|
||||
# from upsert_monthly_active_user_txn because then I need a _txn form of
|
||||
|
@ -271,11 +265,11 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
|||
# _initialise_reserved_users reasoning that it would be very strange to
|
||||
# include a support user in this context.
|
||||
|
||||
is_support = yield self.is_support_user(user_id)
|
||||
is_support = await self.is_support_user(user_id)
|
||||
if is_support:
|
||||
return
|
||||
|
||||
yield self.db_pool.runInteraction(
|
||||
await self.db_pool.runInteraction(
|
||||
"upsert_monthly_active_user", self.upsert_monthly_active_user_txn, user_id
|
||||
)
|
||||
|
||||
|
@ -322,8 +316,7 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
|||
|
||||
return is_insert
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def populate_monthly_active_users(self, user_id):
|
||||
async def populate_monthly_active_users(self, user_id):
|
||||
"""Checks on the state of monthly active user limits and optionally
|
||||
add the user to the monthly active tables
|
||||
|
||||
|
@ -332,14 +325,14 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
|||
"""
|
||||
if self._limit_usage_by_mau or self._mau_stats_only:
|
||||
# Trial users and guests should not be included as part of MAU group
|
||||
is_guest = yield self.is_guest(user_id)
|
||||
is_guest = await self.is_guest(user_id)
|
||||
if is_guest:
|
||||
return
|
||||
is_trial = yield self.is_trial_user(user_id)
|
||||
is_trial = await self.is_trial_user(user_id)
|
||||
if is_trial:
|
||||
return
|
||||
|
||||
last_seen_timestamp = yield self.user_last_seen_monthly_active(user_id)
|
||||
last_seen_timestamp = await self.user_last_seen_monthly_active(user_id)
|
||||
now = self.hs.get_clock().time_msec()
|
||||
|
||||
# We want to reduce to the total number of db writes, and are happy
|
||||
|
@ -352,10 +345,10 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
|||
# False, there is no point in checking get_monthly_active_count - it
|
||||
# adds no value and will break the logic if max_mau_value is exceeded.
|
||||
if not self._limit_usage_by_mau:
|
||||
yield self.upsert_monthly_active_user(user_id)
|
||||
await self.upsert_monthly_active_user(user_id)
|
||||
else:
|
||||
count = yield self.get_monthly_active_count()
|
||||
count = await self.get_monthly_active_count()
|
||||
if count < self._max_mau_value:
|
||||
yield self.upsert_monthly_active_user(user_id)
|
||||
await self.upsert_monthly_active_user(user_id)
|
||||
elif now - last_seen_timestamp > LAST_SEEN_GRANULARITY:
|
||||
yield self.upsert_monthly_active_user(user_id)
|
||||
await self.upsert_monthly_active_user(user_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue