This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Reduce state pulled from DB due to sending typing and receipts over federation #12964
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1d81d4e
Pull current hosts out from current_state table
erikjohnston f10144b
Use get_current_hosts_in_room in typing handler
erikjohnston 84eb1c8
Newsfile
erikjohnston 0438d17
Fix tests
erikjohnston 4e3bca9
Update tests/federation/test_federation_sender.py
erikjohnston 9b1c2a8
Merge newsfile
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reduce the amount of state we pull from the DB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -893,6 +893,43 @@ async def _check_host_room_membership( | |
|
||
return True | ||
|
||
@cached(iterable=True, max_entries=10000) | ||
async def get_current_hosts_in_room(self, room_id: str) -> Set[str]: | ||
"""Get current hosts in room based on current state.""" | ||
|
||
# First we check if we already have `get_users_in_room` in the cache, as | ||
# we can just calculate result from that | ||
users = self.get_users_in_room.cache.get_immediate( | ||
(room_id,), None, update_metrics=False | ||
) | ||
if users is not None: | ||
return {get_domain_from_id(u) for u in users} | ||
|
||
if isinstance(self.database_engine, Sqlite3Engine): | ||
# If we're using SQLite then let's just always use | ||
# `get_users_in_room` rather than funky SQL. | ||
users = await self.get_users_in_room(room_id) | ||
return {get_domain_from_id(u) for u in users} | ||
|
||
# For PostgreSQL we can use a regex to pull out the domains from the | ||
# joined users in `current_state_events` via regex. | ||
|
||
def get_current_hosts_in_room_txn(txn: LoggingTransaction) -> Set[str]: | ||
sql = """ | ||
SELECT DISTINCT substring(state_key FROM '@[^:]*:(.*)$') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex seems to match |
||
FROM current_state_events | ||
WHERE | ||
type = 'm.room.member' | ||
AND membership = 'join' | ||
AND room_id = ? | ||
""" | ||
txn.execute(sql, (room_id,)) | ||
return {d for d, in txn} | ||
|
||
return await self.db_pool.runInteraction( | ||
"get_current_hosts_in_room", get_current_hosts_in_room_txn | ||
) | ||
|
||
async def get_joined_hosts( | ||
self, room_id: str, state_entry: "_StateCacheEntry" | ||
) -> FrozenSet[str]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is because the SQL doesn't work on SQLite (or it would need a different dialect?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, exactly