Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
31fa7435
Commit
31fa7435
authored
6 years ago
by
Neil Johnson
Browse files
Options
Downloads
Patches
Plain Diff
fix sqlite/postgres incompatibility in reap_monthly_active_users
parent
a001038b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/monthly_active_users.py
+28
-16
28 additions, 16 deletions
synapse/storage/monthly_active_users.py
with
28 additions
and
16 deletions
synapse/storage/monthly_active_users.py
+
28
−
16
View file @
31fa7435
...
...
@@ -64,23 +64,27 @@ class MonthlyActiveUsersStore(SQLBaseStore):
Deferred[]
"""
def
_reap_users
(
txn
):
# Purge stale users
thirty_days_ago
=
(
int
(
self
.
_clock
.
time_msec
())
-
(
1000
*
60
*
60
*
24
*
30
)
)
# Purge stale users
# questionmarks is a hack to overcome sqlite not supporting
# tuples in 'WHERE IN %s'
questionmarks
=
'
?
'
*
len
(
self
.
reserved_users
)
query_args
=
[
thirty_days_ago
]
query_args
.
extend
(
self
.
reserved_users
)
sql
=
"""
DELETE FROM monthly_active_users
WHERE timestamp < ?
AND user_id NOT IN ({})
"""
.
format
(
'
,
'
.
join
(
questionmarks
))
base_sql
=
"
DELETE FROM monthly_active_users WHERE timestamp < ?
"
# Need if/else since 'AND user_id NOT IN ({})' fails on Postgres
# when len(reserved_users) == 0. Works fine on sqlite.
if
len
(
self
.
reserved_users
)
>
0
:
# questionmarks is a hack to overcome sqlite not supporting
# tuples in 'WHERE IN %s'
questionmarks
=
'
?
'
*
len
(
self
.
reserved_users
)
query_args
.
extend
(
self
.
reserved_users
)
sql
=
base_sql
+
"""
AND user_id NOT IN ({})
"""
.
format
(
'
,
'
.
join
(
questionmarks
)
)
else
:
sql
=
base_sql
txn
.
execute
(
sql
,
query_args
)
...
...
@@ -93,16 +97,24 @@ class MonthlyActiveUsersStore(SQLBaseStore):
# negative LIMIT values. So there is no way to write it that both can
# support
query_args
=
[
self
.
hs
.
config
.
max_mau_value
]
query_args
.
extend
(
self
.
reserved_users
)
sql
=
"""
base_
sql
=
"""
DELETE FROM monthly_active_users
WHERE user_id NOT IN (
SELECT user_id FROM monthly_active_users
ORDER BY timestamp DESC
LIMIT ?
)
AND user_id NOT IN ({})
"""
.
format
(
'
,
'
.
join
(
questionmarks
))
"""
# Need if/else since 'AND user_id NOT IN ({})' fails on Postgres
# when len(reserved_users) == 0. Works fine on sqlite.
if
len
(
self
.
reserved_users
)
>
0
:
query_args
.
extend
(
self
.
reserved_users
)
sql
=
base_sql
+
"""
AND user_id NOT IN ({})
"""
.
format
(
'
,
'
.
join
(
questionmarks
)
)
else
:
sql
=
base_sql
txn
.
execute
(
sql
,
query_args
)
yield
self
.
runInteraction
(
"
reap_monthly_active_users
"
,
_reap_users
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment