mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Fix postgres compatibility bug
This commit is contained in:
parent
1911c037cb
commit
e54794f5b6
@ -43,14 +43,25 @@ class MonthlyActiveUsersStore(SQLBaseStore):
|
|||||||
thirty_days_ago = (
|
thirty_days_ago = (
|
||||||
int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30)
|
int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30)
|
||||||
)
|
)
|
||||||
|
# Purge stale users
|
||||||
sql = "DELETE FROM monthly_active_users WHERE timestamp < ?"
|
sql = "DELETE FROM monthly_active_users WHERE timestamp < ?"
|
||||||
|
|
||||||
txn.execute(sql, (thirty_days_ago,))
|
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 = """
|
sql = """
|
||||||
DELETE FROM monthly_active_users
|
DELETE FROM monthly_active_users
|
||||||
ORDER BY timestamp desc
|
WHERE user_id NOT IN (
|
||||||
LIMIT -1 OFFSET ?
|
SELECT user_id FROM monthly_active_users
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT ?
|
||||||
|
)
|
||||||
"""
|
"""
|
||||||
txn.execute(sql, (self.hs.config.max_mau_value,))
|
txn.execute(sql, (self.hs.config.max_mau_value,))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user