Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
fefe9943
Unverified
Commit
fefe9943
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert presence handler helpers to async/await. (#7939)
parent
83434df3
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
changelog.d/7939.misc
+1
-0
1 addition, 0 deletions
changelog.d/7939.misc
synapse/federation/sender/__init__.py
+3
-1
3 additions, 1 deletion
synapse/federation/sender/__init__.py
synapse/handlers/presence.py
+20
-23
20 additions, 23 deletions
synapse/handlers/presence.py
with
24 additions
and
24 deletions
changelog.d/7939.misc
0 → 100644
+
1
−
0
View file @
fefe9943
Convert presence handler helpers to async/await.
This diff is collapsed.
Click to expand it.
synapse/federation/sender/__init__.py
+
3
−
1
View file @
fefe9943
...
...
@@ -453,7 +453,9 @@ class FederationSender(object):
"""
Given a list of states populate self.pending_presence_by_dest and
poke to send a new transaction to each destination
"""
hosts_and_states
=
yield
get_interested_remotes
(
self
.
store
,
states
,
self
.
state
)
hosts_and_states
=
yield
defer
.
ensureDeferred
(
get_interested_remotes
(
self
.
store
,
states
,
self
.
state
)
)
for
destinations
,
states
in
hosts_and_states
:
for
destination
in
destinations
:
...
...
This diff is collapsed.
Click to expand it.
synapse/handlers/presence.py
+
20
−
23
View file @
fefe9943
...
...
@@ -30,8 +30,6 @@ from typing import Dict, Iterable, List, Set, Tuple
from
prometheus_client
import
Counter
from
typing_extensions
import
ContextManager
from
twisted.internet
import
defer
import
synapse.metrics
from
synapse.api.constants
import
EventTypes
,
Membership
,
PresenceState
from
synapse.api.errors
import
SynapseError
...
...
@@ -39,6 +37,8 @@ from synapse.logging.context import run_in_background
from
synapse.logging.utils
import
log_function
from
synapse.metrics
import
LaterGauge
from
synapse.metrics.background_process_metrics
import
run_as_background_process
from
synapse.state
import
StateHandler
from
synapse.storage.data_stores.main
import
DataStore
from
synapse.storage.presence
import
UserPresenceState
from
synapse.types
import
JsonDict
,
UserID
,
get_domain_from_id
from
synapse.util.async_helpers
import
Linearizer
...
...
@@ -895,16 +895,9 @@ class PresenceHandler(BasePresenceHandler):
await
self
.
_on_user_joined_room
(
room_id
,
state_key
)
async
def
_on_user_joined_room
(
self
,
room_id
,
user_id
)
:
async
def
_on_user_joined_room
(
self
,
room_id
:
str
,
user_id
:
str
)
->
None
:
"""
Called when we detect a user joining the room via the current state
delta stream.
Args:
room_id (str)
user_id (str)
Returns:
Deferred
"""
if
self
.
is_mine_id
(
user_id
):
...
...
@@ -1296,22 +1289,24 @@ def handle_update(prev_state, new_state, is_mine, wheel_timer, now):
return
new_state
,
persist_and_notify
,
federation_ping
@defer.inlineCallbacks
def
get_interested_parties
(
store
,
states
):
async
def
get_interested_parties
(
store
:
DataStore
,
states
:
List
[
UserPresenceState
]
)
->
Tuple
[
Dict
[
str
,
List
[
UserPresenceState
]],
Dict
[
str
,
List
[
UserPresenceState
]]]:
"""
Given a list of states return which entities (rooms, users)
are interested in the given states.
Args:
states (list(UserPresenceState))
store
states
Returns:
2-tuple
:
`(room_ids_to_states, users_to_states)`,
A
2-tuple
of
`(room_ids_to_states, users_to_states)`,
with each item being a dict of `entity_name` -> `[UserPresenceState]`
"""
room_ids_to_states
=
{}
# type: Dict[str, List[UserPresenceState]]
users_to_states
=
{}
# type: Dict[str, List[UserPresenceState]]
for
state
in
states
:
room_ids
=
yield
store
.
get_rooms_for_user
(
state
.
user_id
)
room_ids
=
await
store
.
get_rooms_for_user
(
state
.
user_id
)
for
room_id
in
room_ids
:
room_ids_to_states
.
setdefault
(
room_id
,
[]).
append
(
state
)
...
...
@@ -1321,20 +1316,22 @@ def get_interested_parties(store, states):
return
room_ids_to_states
,
users_to_states
@defer.inlineCallbacks
def
get_interested_remotes
(
store
,
states
,
state_handler
):
async
def
get_interested_remotes
(
store
:
DataStore
,
states
:
List
[
UserPresenceState
],
state_handler
:
StateHandler
)
->
List
[
Tuple
[
List
[
str
],
List
[
UserPresenceState
]]]:
"""
Given a list of presence states figure out which remote servers
should be sent which.
All the presence states should be for local users only.
Args:
store (DataStore)
states (list(UserPresenceState))
store
states
state_handler
Returns:
Deferred
list of
([destinations], [UserPresenceS
tate
])
, where for
each
row
the list of UserPresenceState should be sent to each
A
list of
2-tuples of destinations and s
tate
s
, where for
each
tuple
the list of UserPresenceState should be sent to each
destination
"""
hosts_and_states
=
[]
...
...
@@ -1342,10 +1339,10 @@ def get_interested_remotes(store, states, state_handler):
# First we look up the rooms each user is in (as well as any explicit
# subscriptions), then for each distinct room we look up the remote
# hosts in those rooms.
room_ids_to_states
,
users_to_states
=
yield
get_interested_parties
(
store
,
states
)
room_ids_to_states
,
users_to_states
=
await
get_interested_parties
(
store
,
states
)
for
room_id
,
states
in
room_ids_to_states
.
items
():
hosts
=
yield
state_handler
.
get_current_hosts_in_room
(
room_id
)
hosts
=
await
state_handler
.
get_current_hosts_in_room
(
room_id
)
hosts_and_states
.
append
((
hosts
,
states
))
for
user_id
,
states
in
users_to_states
.
items
():
...
...
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