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
d3c30264
Commit
d3c30264
authored
7 years ago
by
Erik Johnston
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2201 from matrix-org/erikj/store_device_cache
Cache check to see if device exists
parents
b9c84f3f
6a12998a
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
+22
-3
22 additions, 3 deletions
synapse/storage/devices.py
with
22 additions
and
3 deletions
synapse/storage/devices.py
+
22
−
3
View file @
d3c30264
...
...
@@ -18,7 +18,7 @@ import ujson as json
from
twisted.internet
import
defer
from
synapse.api.errors
import
StoreError
from
._base
import
SQLBaseStore
from
._base
import
SQLBaseStore
,
Cache
from
synapse.util.caches.descriptors
import
cached
,
cachedList
,
cachedInlineCallbacks
...
...
@@ -29,6 +29,14 @@ class DeviceStore(SQLBaseStore):
def
__init__
(
self
,
hs
):
super
(
DeviceStore
,
self
).
__init__
(
hs
)
# Map of (user_id, device_id) -> bool. If there is an entry that implies
# the device exists.
self
.
device_id_exists_cache
=
Cache
(
name
=
"
device_id_exists
"
,
keylen
=
2
,
max_entries
=
10000
,
)
self
.
_clock
.
looping_call
(
self
.
_prune_old_outbound_device_pokes
,
60
*
60
*
1000
)
...
...
@@ -54,6 +62,10 @@ class DeviceStore(SQLBaseStore):
defer.Deferred: boolean whether the device was inserted or an
existing device existed with that ID.
"""
key
=
(
user_id
,
device_id
)
if
self
.
device_id_exists_cache
.
get
(
key
,
None
):
defer
.
returnValue
(
False
)
try
:
inserted
=
yield
self
.
_simple_insert
(
"
devices
"
,
...
...
@@ -65,6 +77,7 @@ class DeviceStore(SQLBaseStore):
desc
=
"
store_device
"
,
or_ignore
=
True
,
)
self
.
device_id_exists_cache
.
prefill
(
key
,
True
)
defer
.
returnValue
(
inserted
)
except
Exception
as
e
:
logger
.
error
(
"
store_device with device_id=%s(%r) user_id=%s(%r)
"
...
...
@@ -93,6 +106,7 @@ class DeviceStore(SQLBaseStore):
desc
=
"
get_device
"
,
)
@defer.inlineCallbacks
def
delete_device
(
self
,
user_id
,
device_id
):
"""
Delete a device.
...
...
@@ -102,12 +116,15 @@ class DeviceStore(SQLBaseStore):
Returns:
defer.Deferred
"""
return
self
.
_simple_delete_one
(
yield
self
.
_simple_delete_one
(
table
=
"
devices
"
,
keyvalues
=
{
"
user_id
"
:
user_id
,
"
device_id
"
:
device_id
},
desc
=
"
delete_device
"
,
)
self
.
device_id_exists_cache
.
invalidate
((
user_id
,
device_id
))
@defer.inlineCallbacks
def
delete_devices
(
self
,
user_id
,
device_ids
):
"""
Deletes several devices.
...
...
@@ -117,13 +134,15 @@ class DeviceStore(SQLBaseStore):
Returns:
defer.Deferred
"""
return
self
.
_simple_delete_many
(
yield
self
.
_simple_delete_many
(
table
=
"
devices
"
,
column
=
"
device_id
"
,
iterable
=
device_ids
,
keyvalues
=
{
"
user_id
"
:
user_id
},
desc
=
"
delete_devices
"
,
)
for
device_id
in
device_ids
:
self
.
device_id_exists_cache
.
invalidate
((
user_id
,
device_id
))
def
update_device
(
self
,
user_id
,
device_id
,
new_display_name
=
None
):
"""
Update a device.
...
...
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