Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Speed up get_current_state_ids #2108

Merged
merged 2 commits into from
Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

from ._base import SQLBaseStore
from synapse.util.caches.descriptors import cached, cachedList, cachedInlineCallbacks
from synapse.util.caches.descriptors import cached, cachedList
from synapse.util.caches import intern_string
from synapse.storage.engines import PostgresEngine

Expand Down Expand Up @@ -69,17 +69,33 @@ def __init__(self, hs):
where_clause="type='m.room.member'",
)

@cachedInlineCallbacks(max_entries=100000, iterable=True)
@cached(max_entries=100000, iterable=True)
def get_current_state_ids(self, room_id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc string please. It's now harder to see by inspection what it returns.

rows = yield self._simple_select_list(
table="current_state_events",
keyvalues={"room_id": room_id},
retcols=["event_id", "type", "state_key"],
desc="_calculate_state_delta",
"""Get the current state event ids for a room based on the
current_state_events table.

Args:
room_id (str)

Returns:
deferred: dict of (type, state_key) -> event_id
"""
def _get_current_state_ids_txn(txn):
txn.execute(
"""SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = ?
""",
(room_id,)
)

return {
(r[0], r[1]): r[2] for r in txn
}

return self.runInteraction(
"get_current_state_ids",
_get_current_state_ids_txn,
)
defer.returnValue({
(r["type"], r["state_key"]): r["event_id"] for r in rows
})

@defer.inlineCallbacks
def get_state_groups_ids(self, room_id, event_ids):
Expand Down