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
d7457c76
Commit
d7457c76
authored
8 years ago
by
Erik Johnston
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1914 from matrix-org/erikj/cache_presence
Cache get_presence storage
parents
359c97f5
9e617cd4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/presence.py
+1
-1
1 addition, 1 deletion
synapse/handlers/presence.py
synapse/replication/slave/storage/presence.py
+3
-1
3 additions, 1 deletion
synapse/replication/slave/storage/presence.py
synapse/storage/presence.py
+11
-3
11 additions, 3 deletions
synapse/storage/presence.py
with
15 additions
and
5 deletions
synapse/handlers/presence.py
+
1
−
1
View file @
d7457c76
...
...
@@ -531,7 +531,7 @@ class PresenceHandler(object):
# There are things not in our in memory cache. Lets pull them out of
# the database.
res
=
yield
self
.
store
.
get_presence_for_users
(
missing
)
states
.
update
(
{
state
.
user_id
:
state
for
state
in
res
}
)
states
.
update
(
res
)
missing
=
[
user_id
for
user_id
,
state
in
states
.
items
()
if
not
state
]
if
missing
:
...
...
This diff is collapsed.
Click to expand it.
synapse/replication/slave/storage/presence.py
+
3
−
1
View file @
d7457c76
...
...
@@ -18,6 +18,7 @@ from ._slaved_id_tracker import SlavedIdTracker
from
synapse.util.caches.stream_change_cache
import
StreamChangeCache
from
synapse.storage
import
DataStore
from
synapse.storage.presence
import
PresenceStore
class
SlavedPresenceStore
(
BaseSlavedStore
):
...
...
@@ -35,7 +36,8 @@ class SlavedPresenceStore(BaseSlavedStore):
_get_active_presence
=
DataStore
.
_get_active_presence
.
__func__
take_presence_startup_info
=
DataStore
.
take_presence_startup_info
.
__func__
get_presence_for_users
=
DataStore
.
get_presence_for_users
.
__func__
_get_presence_for_user
=
PresenceStore
.
__dict__
[
"
_get_presence_for_user
"
]
get_presence_for_users
=
PresenceStore
.
__dict__
[
"
get_presence_for_users
"
]
def
get_current_presence_token
(
self
):
return
self
.
_presence_id_gen
.
get_current_token
()
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/presence.py
+
11
−
3
View file @
d7457c76
...
...
@@ -15,7 +15,7 @@
from
._base
import
SQLBaseStore
from
synapse.api.constants
import
PresenceState
from
synapse.util.caches.descriptors
import
cached
,
cachedInlineCallbacks
from
synapse.util.caches.descriptors
import
cached
,
cachedInlineCallbacks
,
cachedList
from
collections
import
namedtuple
from
twisted.internet
import
defer
...
...
@@ -85,6 +85,9 @@ class PresenceStore(SQLBaseStore):
self
.
presence_stream_cache
.
entity_has_changed
,
state
.
user_id
,
stream_id
,
)
self
.
_invalidate_cache_and_stream
(
txn
,
self
.
_get_presence_for_user
,
(
state
.
user_id
,)
)
# Actually insert new rows
self
.
_simple_insert_many_txn
(
...
...
@@ -143,7 +146,12 @@ class PresenceStore(SQLBaseStore):
"
get_all_presence_updates
"
,
get_all_presence_updates_txn
)
@defer.inlineCallbacks
@cached
()
def
_get_presence_for_user
(
self
,
user_id
):
raise
NotImplementedError
()
@cachedList
(
cached_method_name
=
"
_get_presence_for_user
"
,
list_name
=
"
user_ids
"
,
num_args
=
1
,
inlineCallbacks
=
True
)
def
get_presence_for_users
(
self
,
user_ids
):
rows
=
yield
self
.
_simple_select_many_batch
(
table
=
"
presence_stream
"
,
...
...
@@ -165,7 +173,7 @@ class PresenceStore(SQLBaseStore):
for
row
in
rows
:
row
[
"
currently_active
"
]
=
bool
(
row
[
"
currently_active
"
])
defer
.
returnValue
(
[
UserPresenceState
(
**
row
)
for
row
in
rows
]
)
defer
.
returnValue
(
{
row
[
"
user_id
"
]:
UserPresenceState
(
**
row
)
for
row
in
rows
}
)
def
get_current_presence_token
(
self
):
return
self
.
_presence_id_gen
.
get_current_token
()
...
...
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