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
d360c97a
Commit
d360c97a
authored
8 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Clear out old destination pokes.
parent
76100203
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/devices.py
+42
-0
42 additions, 0 deletions
synapse/storage/devices.py
with
42 additions
and
0 deletions
synapse/storage/devices.py
+
42
−
0
View file @
d360c97a
...
...
@@ -24,6 +24,13 @@ logger = logging.getLogger(__name__)
class
DeviceStore
(
SQLBaseStore
):
def
__init__
(
self
,
hs
):
super
(
DeviceStore
,
self
).
__init__
(
hs
)
self
.
_clock
.
looping_call
(
self
.
_prune_old_outbound_device_pokes
,
60
*
60
*
1000
)
@defer.inlineCallbacks
def
store_device
(
self
,
user_id
,
device_id
,
initial_device_display_name
):
...
...
@@ -530,3 +537,38 @@ class DeviceStore(SQLBaseStore):
def
get_device_stream_token
(
self
):
return
self
.
_device_list_id_gen
.
get_current_token
()
def
_prune_old_outbound_device_pokes
(
self
):
"""
Delete old entries out of the device_lists_outbound_pokes to ensure
that we don
'
t fill up due to dead servers. We keep one entry per
(destination, user_id) tuple to ensure that the prev_ids remain correct
if the server does come back.
"""
now
=
self
.
_clock
.
time_msec
()
def
_prune_txn
(
txn
):
select_sql
=
"""
SELECT destination, user_id, max(stream_id) as stream_id
FROM device_lists_outbound_pokes
GROUP BY destination, user_id
"""
txn
.
execute
(
select_sql
)
rows
=
txn
.
fetchall
()
delete_sql
=
"""
DELETE FROM device_lists_outbound_pokes
WHERE ts < ? AND destination = ? AND user_id = ? AND stream_id < ?
"""
txn
.
executemany
(
delete_sql
,
(
(
now
,
row
[
"
destination
"
],
row
[
"
user_id
"
],
row
[
"
stream_id
"
])
for
row
in
rows
)
)
return
self
.
runInteraction
(
"
_prune_old_outbound_device_pokes
"
,
_prune_txn
)
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