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
Container Registry
Model registry
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
Maunium
synapse
Commits
f9bc5428
Unverified
Commit
f9bc5428
authored
2 years ago
by
Nick Mills-Barrett
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Batch up calls to `get_rooms_for_users` (#14109)
parent
09be8ab5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/14109.misc
+1
-0
1 addition, 0 deletions
changelog.d/14109.misc
synapse/storage/databases/main/roommember.py
+16
-1
16 additions, 1 deletion
synapse/storage/databases/main/roommember.py
with
17 additions
and
1 deletion
changelog.d/14109.misc
0 → 100644
+
1
−
0
View file @
f9bc5428
Break up calls to fetch rooms for many users. Contributed by Nick @ Beeper (@fizzadar).
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/roommember.py
+
16
−
1
View file @
f9bc5428
...
...
@@ -666,7 +666,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
cached_method_name
=
"
get_rooms_for_user
"
,
list_name
=
"
user_ids
"
,
)
async
def
get_rooms_for_users
(
async
def
_
get_rooms_for_users
(
self
,
user_ids
:
Collection
[
str
]
)
->
Dict
[
str
,
FrozenSet
[
str
]]:
"""
A batched version of `get_rooms_for_user`.
...
...
@@ -697,6 +697,21 @@ class RoomMemberWorkerStore(EventsWorkerStore):
return
{
key
:
frozenset
(
rooms
)
for
key
,
rooms
in
user_rooms
.
items
()}
async
def
get_rooms_for_users
(
self
,
user_ids
:
Collection
[
str
]
)
->
Dict
[
str
,
FrozenSet
[
str
]]:
"""
A batched wrapper around `_get_rooms_for_users`, to prevent locking
other calls to `get_rooms_for_user` for large user lists.
"""
all_user_rooms
:
Dict
[
str
,
FrozenSet
[
str
]]
=
{}
# 250 users is pretty arbitrary but the data can be quite large if users
# are in many rooms.
for
user_ids
in
batch_iter
(
user_ids
,
250
):
all_user_rooms
.
update
(
await
self
.
_get_rooms_for_users
(
user_ids
))
return
all_user_rooms
@cached
(
max_entries
=
10000
)
async
def
does_pair_of_users_share_a_room
(
self
,
user_id
:
str
,
other_user_id
:
str
...
...
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