inline some config references
parent
b3a9ad124c
commit
1c347c84bf
|
@ -403,8 +403,10 @@ class EventCreationHandler(object):
|
||||||
if self._block_events_without_consent_error:
|
if self._block_events_without_consent_error:
|
||||||
self._consent_uri_builder = ConsentURIBuilder(self.config)
|
self._consent_uri_builder = ConsentURIBuilder(self.config)
|
||||||
|
|
||||||
|
self._is_worker_app = self.config.worker_app is not None
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not self.config.worker_app
|
not self._is_worker_app
|
||||||
and self.config.cleanup_extremities_with_dummy_events
|
and self.config.cleanup_extremities_with_dummy_events
|
||||||
):
|
):
|
||||||
self.clock.looping_call(
|
self.clock.looping_call(
|
||||||
|
@ -824,7 +826,7 @@ class EventCreationHandler(object):
|
||||||
success = False
|
success = False
|
||||||
try:
|
try:
|
||||||
# If we're a worker we need to hit out to the master.
|
# If we're a worker we need to hit out to the master.
|
||||||
if self.config.worker_app:
|
if self._is_worker_app:
|
||||||
await self.send_event_to_master(
|
await self.send_event_to_master(
|
||||||
event_id=event.event_id,
|
event_id=event.event_id,
|
||||||
store=self.store,
|
store=self.store,
|
||||||
|
@ -890,7 +892,7 @@ class EventCreationHandler(object):
|
||||||
|
|
||||||
This should only be run on master.
|
This should only be run on master.
|
||||||
"""
|
"""
|
||||||
assert not self.config.worker_app
|
assert not self._is_worker_app
|
||||||
|
|
||||||
if ratelimit:
|
if ratelimit:
|
||||||
# We check if this is a room admin redacting an event so that we
|
# We check if this is a room admin redacting an event so that we
|
||||||
|
|
|
@ -48,6 +48,12 @@ class ResourceLimitsServerNotices(object):
|
||||||
|
|
||||||
self._notifier = hs.get_notifier()
|
self._notifier = hs.get_notifier()
|
||||||
|
|
||||||
|
self._enabled = (
|
||||||
|
hs.config.limit_usage_by_mau
|
||||||
|
and self._server_notices_manager.is_enabled()
|
||||||
|
and not hs.config.hs_disabled
|
||||||
|
)
|
||||||
|
|
||||||
async def maybe_send_server_notice_to_user(self, user_id):
|
async def maybe_send_server_notice_to_user(self, user_id):
|
||||||
"""Check if we need to send a notice to this user, this will be true in
|
"""Check if we need to send a notice to this user, this will be true in
|
||||||
two cases.
|
two cases.
|
||||||
|
@ -61,14 +67,7 @@ class ResourceLimitsServerNotices(object):
|
||||||
Returns:
|
Returns:
|
||||||
Deferred
|
Deferred
|
||||||
"""
|
"""
|
||||||
if self._config.hs_disabled is True:
|
if not self._enabled:
|
||||||
return
|
|
||||||
|
|
||||||
if self._config.limit_usage_by_mau is False:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self._server_notices_manager.is_enabled():
|
|
||||||
# Don't try and send server notices unless they've been enabled
|
|
||||||
return
|
return
|
||||||
|
|
||||||
timestamp = await self._store.user_last_seen_monthly_active(user_id)
|
timestamp = await self._store.user_last_seen_monthly_active(user_id)
|
||||||
|
|
|
@ -122,6 +122,10 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
def __init__(self, database: Database, db_conn, hs):
|
def __init__(self, database: Database, db_conn, hs):
|
||||||
super(MonthlyActiveUsersStore, self).__init__(database, db_conn, hs)
|
super(MonthlyActiveUsersStore, self).__init__(database, db_conn, hs)
|
||||||
|
|
||||||
|
self._limit_usage_by_mau = hs.config.limit_usage_by_mau
|
||||||
|
self._mau_stats_only = hs.config.mau_stats_only
|
||||||
|
self._max_mau_value = hs.config.max_mau_value
|
||||||
|
|
||||||
# Do not add more reserved users than the total allowable number
|
# Do not add more reserved users than the total allowable number
|
||||||
# cur = LoggingTransaction(
|
# cur = LoggingTransaction(
|
||||||
self.db.new_transaction(
|
self.db.new_transaction(
|
||||||
|
@ -130,7 +134,7 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
self._initialise_reserved_users,
|
self._initialise_reserved_users,
|
||||||
hs.config.mau_limits_reserved_threepids[: self.hs.config.max_mau_value],
|
hs.config.mau_limits_reserved_threepids[: self._max_mau_value],
|
||||||
)
|
)
|
||||||
|
|
||||||
def _initialise_reserved_users(self, txn, threepids):
|
def _initialise_reserved_users(self, txn, threepids):
|
||||||
|
@ -191,8 +195,7 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
|
|
||||||
txn.execute(sql, query_args)
|
txn.execute(sql, query_args)
|
||||||
|
|
||||||
max_mau_value = self.hs.config.max_mau_value
|
if self._limit_usage_by_mau:
|
||||||
if self.hs.config.limit_usage_by_mau:
|
|
||||||
# If MAU user count still exceeds the MAU threshold, then delete on
|
# If MAU user count still exceeds the MAU threshold, then delete on
|
||||||
# a least recently active basis.
|
# a least recently active basis.
|
||||||
# Note it is not possible to write this query using OFFSET due to
|
# Note it is not possible to write this query using OFFSET due to
|
||||||
|
@ -210,13 +213,13 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
txn.execute(sql, (max_mau_value,))
|
txn.execute(sql, ((self._max_mau_value),))
|
||||||
# Need if/else since 'AND user_id NOT IN ({})' fails on Postgres
|
# Need if/else since 'AND user_id NOT IN ({})' fails on Postgres
|
||||||
# when len(reserved_users) == 0. Works fine on sqlite.
|
# when len(reserved_users) == 0. Works fine on sqlite.
|
||||||
else:
|
else:
|
||||||
# Must be >= 0 for postgres
|
# Must be >= 0 for postgres
|
||||||
num_of_non_reserved_users_to_remove = max(
|
num_of_non_reserved_users_to_remove = max(
|
||||||
max_mau_value - len(reserved_users), 0
|
self._max_mau_value - len(reserved_users), 0
|
||||||
)
|
)
|
||||||
|
|
||||||
# It is important to filter reserved users twice to guard
|
# It is important to filter reserved users twice to guard
|
||||||
|
@ -335,7 +338,7 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
Args:
|
Args:
|
||||||
user_id(str): the user_id to query
|
user_id(str): the user_id to query
|
||||||
"""
|
"""
|
||||||
if self.hs.config.limit_usage_by_mau or self.hs.config.mau_stats_only:
|
if self._limit_usage_by_mau or self._mau_stats_only:
|
||||||
# Trial users and guests should not be included as part of MAU group
|
# Trial users and guests should not be included as part of MAU group
|
||||||
is_guest = yield self.is_guest(user_id)
|
is_guest = yield self.is_guest(user_id)
|
||||||
if is_guest:
|
if is_guest:
|
||||||
|
@ -356,11 +359,11 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore):
|
||||||
# In the case where mau_stats_only is True and limit_usage_by_mau is
|
# In the case where mau_stats_only is True and limit_usage_by_mau is
|
||||||
# False, there is no point in checking get_monthly_active_count - it
|
# 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.
|
# adds no value and will break the logic if max_mau_value is exceeded.
|
||||||
if not self.hs.config.limit_usage_by_mau:
|
if not self._limit_usage_by_mau:
|
||||||
yield self.upsert_monthly_active_user(user_id)
|
yield self.upsert_monthly_active_user(user_id)
|
||||||
else:
|
else:
|
||||||
count = yield self.get_monthly_active_count()
|
count = yield self.get_monthly_active_count()
|
||||||
if count < self.hs.config.max_mau_value:
|
if count < self._max_mau_value:
|
||||||
yield self.upsert_monthly_active_user(user_id)
|
yield self.upsert_monthly_active_user(user_id)
|
||||||
elif now - last_seen_timestamp > LAST_SEEN_GRANULARITY:
|
elif now - last_seen_timestamp > LAST_SEEN_GRANULARITY:
|
||||||
yield self.upsert_monthly_active_user(user_id)
|
yield self.upsert_monthly_active_user(user_id)
|
||||||
|
|
Loading…
Reference in New Issue