mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-12 08:36:35 -05:00
Start chagning the events stream to work with the new DB schema
This commit is contained in:
parent
d72f897f07
commit
114984a236
8 changed files with 102 additions and 118 deletions
|
|
@ -104,7 +104,15 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||
|
||||
yield self._simple_insert("state_events", vals)
|
||||
|
||||
# TODO (erikj): We also need to update the current state table?
|
||||
yield self._simple_insert(
|
||||
"current_state_events",
|
||||
{
|
||||
"event_id": event.event_id,
|
||||
"room_id": event.room_id,
|
||||
"type": event.type,
|
||||
"state_key": event.state_key,
|
||||
}
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_current_state(self, room_id, event_type=None, state_key=""):
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ class SQLBaseStore(object):
|
|||
|
||||
def _parse_event_from_row(self, row_dict):
|
||||
d = copy.deepcopy({k: v for k, v in row_dict.items() if v})
|
||||
d.update(json.loads(json.loads(row_dict["unrecognized_keys"])))
|
||||
d.update(json.loads(row_dict["unrecognized_keys"]))
|
||||
d["content"] = json.loads(d["content"])
|
||||
del d["unrecognized_keys"]
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ class RoomMemberStore(SQLBaseStore):
|
|||
yield self._execute(None, sql, event.room_id, domain)
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_member(self, user_id, room_id):
|
||||
"""Retrieve the current state of a room member.
|
||||
|
||||
|
|
@ -72,11 +73,13 @@ class RoomMemberStore(SQLBaseStore):
|
|||
Returns:
|
||||
Deferred: Results in a MembershipEvent or None.
|
||||
"""
|
||||
return self._get_members_by_dict({
|
||||
rows = yield self._get_members_by_dict({
|
||||
"e.room_id": room_id,
|
||||
"m.user_id": user_id,
|
||||
})
|
||||
|
||||
defer.returnValue(rows[0] if rows else None)
|
||||
|
||||
def get_room_members(self, room_id, membership=None):
|
||||
"""Retrieve the current room member list for a room.
|
||||
|
||||
|
|
@ -142,5 +145,8 @@ class RoomMemberStore(SQLBaseStore):
|
|||
) % (where_clause,)
|
||||
|
||||
rows = yield self._execute_and_decode(sql, *where_values)
|
||||
|
||||
logger.debug("_get_members_query Got rows %s", rows)
|
||||
|
||||
results = [self._parse_event_from_row(r) for r in rows]
|
||||
defer.returnValue(results)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ CREATE TABLE IF NOT EXISTS state_events(
|
|||
|
||||
CREATE TABLE IF NOT EXISTS current_state_events(
|
||||
event_id TEXT NOT NULL,
|
||||
room_id TEXT NOT NULL
|
||||
room_id TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
state_key TEXT NOT NULL,
|
||||
CONSTRAINT uniq UNIQUE (room_id, type, state_key) ON CONFLICT REPLACE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS room_memberships(
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class StreamStore(SQLBaseStore):
|
|||
@defer.inlineCallbacks
|
||||
def get_room_events_stream(self, user_id, from_key, to_key, room_id,
|
||||
limit=0, with_feedback=False):
|
||||
# TODO (erikj): Handle compressed feedback
|
||||
|
||||
current_room_membership_sql = (
|
||||
"SELECT m.room_id FROM room_memberships as m "
|
||||
|
|
@ -69,3 +70,33 @@ class StreamStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
defer.returnValue([self._parse_event_from_row(r) for r in rows])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_recent_events_for_room(self, room_id, limit, with_feedback=False):
|
||||
# TODO (erikj): Handle compressed feedback
|
||||
|
||||
sql = (
|
||||
"SELECT * FROM events WHERE room_id = ? "
|
||||
"ORDER BY ordering DESC LIMIT ? "
|
||||
)
|
||||
|
||||
rows = yield self._execute_and_decode(
|
||||
sql,
|
||||
room_id, limit
|
||||
)
|
||||
|
||||
rows.reverse() # As we selected with reverse ordering
|
||||
|
||||
defer.returnValue([self._parse_event_from_row(r) for r in rows])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_events_max_id(self):
|
||||
res = yield self._execute_and_decode(
|
||||
"SELECT MAX(ordering) as m FROM events"
|
||||
)
|
||||
|
||||
if not res:
|
||||
defer.returnValue(0)
|
||||
return
|
||||
|
||||
defer.returnValue(res[0]["m"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue