mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-01-28 16:46:59 -05:00
call reap on start up and fix under reaping bug
This commit is contained in:
parent
372bf073c1
commit
bcfeb44afe
@ -799,7 +799,7 @@ class Auth(object):
|
|||||||
current_mau = yield self.store.get_monthly_active_count()
|
current_mau = yield self.store.get_monthly_active_count()
|
||||||
if current_mau >= self.hs.config.max_mau_value:
|
if current_mau >= self.hs.config.max_mau_value:
|
||||||
raise AuthError(
|
raise AuthError(
|
||||||
403, "Monthly Active User Limits AU Limit Exceeded",
|
403, "Monthly Active User Limit Exceeded",
|
||||||
admin_uri=self.hs.config.admin_uri,
|
admin_uri=self.hs.config.admin_uri,
|
||||||
errcode=Codes.RESOURCE_LIMIT_EXCEED
|
errcode=Codes.RESOURCE_LIMIT_EXCEED
|
||||||
)
|
)
|
||||||
|
@ -525,6 +525,7 @@ def run(hs):
|
|||||||
clock.looping_call(
|
clock.looping_call(
|
||||||
hs.get_datastore().reap_monthly_active_users, 1000 * 60 * 60
|
hs.get_datastore().reap_monthly_active_users, 1000 * 60 * 60
|
||||||
)
|
)
|
||||||
|
yield hs.get_datastore().reap_monthly_active_users()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def generate_monthly_active_users():
|
def generate_monthly_active_users():
|
||||||
|
@ -96,7 +96,10 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
|||||||
# While Postgres does not require 'LIMIT', but also does not support
|
# While Postgres does not require 'LIMIT', but also does not support
|
||||||
# negative LIMIT values. So there is no way to write it that both can
|
# negative LIMIT values. So there is no way to write it that both can
|
||||||
# support
|
# support
|
||||||
query_args = [self.hs.config.max_mau_value]
|
safe_guard = self.hs.config.max_mau_value - len(self.reserved_users)
|
||||||
|
# Must be greater than zero for postgres
|
||||||
|
safe_guard = safe_guard if safe_guard > 0 else 0
|
||||||
|
query_args = [safe_guard]
|
||||||
|
|
||||||
base_sql = """
|
base_sql = """
|
||||||
DELETE FROM monthly_active_users
|
DELETE FROM monthly_active_users
|
||||||
|
@ -75,6 +75,19 @@ class MonthlyActiveUsersTestCase(tests.unittest.TestCase):
|
|||||||
active_count = yield self.store.get_monthly_active_count()
|
active_count = yield self.store.get_monthly_active_count()
|
||||||
self.assertEquals(active_count, user_num)
|
self.assertEquals(active_count, user_num)
|
||||||
|
|
||||||
|
# Test that regalar users are removed from the db
|
||||||
|
ru_count = 2
|
||||||
|
yield self.store.upsert_monthly_active_user("@ru1:server")
|
||||||
|
yield self.store.upsert_monthly_active_user("@ru2:server")
|
||||||
|
active_count = yield self.store.get_monthly_active_count()
|
||||||
|
|
||||||
|
self.assertEqual(active_count, user_num + ru_count)
|
||||||
|
self.hs.config.max_mau_value = user_num
|
||||||
|
yield self.store.reap_monthly_active_users()
|
||||||
|
|
||||||
|
active_count = yield self.store.get_monthly_active_count()
|
||||||
|
self.assertEquals(active_count, user_num)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_can_insert_and_count_mau(self):
|
def test_can_insert_and_count_mau(self):
|
||||||
count = yield self.store.get_monthly_active_count()
|
count = yield self.store.get_monthly_active_count()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user