summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorNeil Johnson <neil@fragile.org.uk>2018-08-06 21:56:56 +0100
committerNeil Johnson <neil@fragile.org.uk>2018-08-06 21:56:56 +0100
commit89834d9a29f67aac052b026bff2f8bab65c33fa7 (patch)
tree887e87974a9cd5293031b4a542ad3be04308dd62 /synapse
parentMerge branch 'neilj/mau_tracker' of github.com:matrix-org/synapse into neilj/... (diff)
parentFix postgres compatibility bug (diff)
downloadsynapse-89834d9a29f67aac052b026bff2f8bab65c33fa7.tar.xz
Merge branch 'neilj/mau_tracker' of github.com:matrix-org/synapse into neilj/disable_hs
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/monthly_active_users.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/synapse/storage/monthly_active_users.py b/synapse/storage/monthly_active_users.py

index c28c698c6c..abe1e6bb99 100644 --- a/synapse/storage/monthly_active_users.py +++ b/synapse/storage/monthly_active_users.py
@@ -43,14 +43,25 @@ class MonthlyActiveUsersStore(SQLBaseStore): thirty_days_ago = ( int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30) ) - + # Purge stale users sql = "DELETE FROM monthly_active_users WHERE timestamp < ?" - txn.execute(sql, (thirty_days_ago,)) + + # If MAU user count still exceeds the MAU threshold, then delete on + # a least recently active basis. + # Note it is not possible to write this query using OFFSET due to + # incompatibilities in how sqlite an postgres support the feature. + # sqlite requires 'LIMIT -1 OFFSET ?', the LIMIT must be present + # 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 + # support sql = """ DELETE FROM monthly_active_users - ORDER BY timestamp desc - LIMIT -1 OFFSET ? + WHERE user_id NOT IN ( + SELECT user_id FROM monthly_active_users + ORDER BY timestamp DESC + LIMIT ? + ) """ txn.execute(sql, (self.hs.config.max_mau_value,))