Optimise some references to hs.config (#7546)

These are surprisingly expensive, and we only really need to do them at startup.
This commit is contained in:
Richard van der Hoff 2020-05-22 21:47:07 +01:00 committed by GitHub
parent 2901f54359
commit f4269694ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 162 additions and 136 deletions

View file

@ -48,6 +48,12 @@ class ResourceLimitsServerNotices(object):
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):
"""Check if we need to send a notice to this user, this will be true in
two cases.
@ -61,14 +67,7 @@ class ResourceLimitsServerNotices(object):
Returns:
Deferred
"""
if self._config.hs_disabled is True:
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
if not self._enabled:
return
timestamp = await self._store.user_last_seen_monthly_active(user_id)