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
8e1ada9e
Commit
8e1ada9e
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Use the current_state_events.membership column
parent
059d8c1a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/roommember.py
+37
-17
37 additions, 17 deletions
synapse/storage/roommember.py
with
37 additions
and
17 deletions
synapse/storage/roommember.py
+
37
−
17
View file @
8e1ada9e
...
@@ -115,14 +115,23 @@ class RoomMemberWorkerStore(EventsWorkerStore):
...
@@ -115,14 +115,23 @@ class RoomMemberWorkerStore(EventsWorkerStore):
@cached
(
max_entries
=
100000
,
iterable
=
True
)
@cached
(
max_entries
=
100000
,
iterable
=
True
)
def
get_users_in_room
(
self
,
room_id
):
def
get_users_in_room
(
self
,
room_id
):
def
f
(
txn
):
def
f
(
txn
):
sql
=
(
# If we can assume current_state_events.membership is up to date
"
SELECT m.user_id FROM room_memberships as m
"
# then we can avoid a join, which is a Very Good Thing given how
"
INNER JOIN current_state_events as c
"
# frequently this function gets called.
"
ON m.event_id = c.event_id
"
if
self
.
_current_state_events_membership_up_to_date
:
"
AND m.room_id = c.room_id
"
sql
=
"""
"
AND m.user_id = c.state_key
"
SELECT state_key FROM current_state_events
"
WHERE c.type =
'
m.room.member
'
AND c.room_id = ? AND m.membership = ?
"
WHERE type =
'
m.room.member
'
AND room_id = ? AND membership = ?
)
"""
else
:
sql
=
"""
SELECT state_key FROM room_memberships as m
INNER JOIN current_state_events as c
ON m.event_id = c.event_id
AND m.room_id = c.room_id
AND m.user_id = c.state_key
WHERE c.type =
'
m.room.member
'
AND c.room_id = ? AND m.membership = ?
"""
txn
.
execute
(
sql
,
(
room_id
,
Membership
.
JOIN
))
txn
.
execute
(
sql
,
(
room_id
,
Membership
.
JOIN
))
return
[
to_ascii
(
r
[
0
])
for
r
in
txn
]
return
[
to_ascii
(
r
[
0
])
for
r
in
txn
]
...
@@ -144,15 +153,26 @@ class RoomMemberWorkerStore(EventsWorkerStore):
...
@@ -144,15 +153,26 @@ class RoomMemberWorkerStore(EventsWorkerStore):
# first get counts.
# first get counts.
# We do this all in one transaction to keep the cache small.
# We do this all in one transaction to keep the cache small.
# FIXME: get rid of this when we have room_stats
# FIXME: get rid of this when we have room_stats
sql
=
"""
SELECT count(*), m.membership FROM room_memberships as m
# If we can assume current_state_events.membership is up to date
INNER JOIN current_state_events as c
# then we can avoid a join, which is a Very Good Thing given how
ON m.event_id = c.event_id
# frequently this function gets called.
AND m.room_id = c.room_id
if
self
.
_current_state_events_membership_up_to_date
:
AND m.user_id = c.state_key
sql
=
"""
WHERE c.type =
'
m.room.member
'
AND c.room_id = ?
SELECT count(*), membership FROM current_state_events
GROUP BY m.membership
WHERE type =
'
m.room.member
'
AND room_id = ?
"""
GROUP BY membership
"""
else
:
sql
=
"""
SELECT count(*), m.membership FROM room_memberships as m
INNER JOIN current_state_events as c
ON m.event_id = c.event_id
AND m.room_id = c.room_id
AND m.user_id = c.state_key
WHERE c.type =
'
m.room.member
'
AND c.room_id = ?
GROUP BY m.membership
"""
txn
.
execute
(
sql
,
(
room_id
,))
txn
.
execute
(
sql
,
(
room_id
,))
res
=
{}
res
=
{}
...
...
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