mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-30 20:58:32 -04:00
Increase DB/CPU perf of _is_server_still_joined
check. (#6936)
* Increase DB/CPU perf of `_is_server_still_joined` check. For rooms with large amount of state a single user leaving could cause us to go and load a lot of membership events and then pull out membership state in a large number of batches. * Newsfile * Update synapse/storage/persist_events.py Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> * Fix adding if too soon * Update docstring * Review comments * Woops typo Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
5e4a438556
commit
0d0bc35792
3 changed files with 60 additions and 15 deletions
|
@ -868,6 +868,37 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||
desc="get_membership_from_event_ids",
|
||||
)
|
||||
|
||||
async def is_local_host_in_room_ignoring_users(
|
||||
self, room_id: str, ignore_users: Collection[str]
|
||||
) -> bool:
|
||||
"""Check if there are any local users, excluding those in the given
|
||||
list, in the room.
|
||||
"""
|
||||
|
||||
clause, args = make_in_list_sql_clause(
|
||||
self.database_engine, "user_id", ignore_users
|
||||
)
|
||||
|
||||
sql = """
|
||||
SELECT 1 FROM local_current_membership
|
||||
WHERE
|
||||
room_id = ? AND membership = ?
|
||||
AND NOT (%s)
|
||||
LIMIT 1
|
||||
""" % (
|
||||
clause,
|
||||
)
|
||||
|
||||
def _is_local_host_in_room_ignoring_users_txn(txn):
|
||||
txn.execute(sql, (room_id, Membership.JOIN, *args))
|
||||
|
||||
return bool(txn.fetchone())
|
||||
|
||||
return await self.db.runInteraction(
|
||||
"is_local_host_in_room_ignoring_users",
|
||||
_is_local_host_in_room_ignoring_users_txn,
|
||||
)
|
||||
|
||||
|
||||
class RoomMemberBackgroundUpdateStore(SQLBaseStore):
|
||||
def __init__(self, database: Database, db_conn, hs):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue