Get correct prev_events
This commit is contained in:
parent
1616df2f61
commit
cc44ecc62f
|
@ -439,7 +439,7 @@ class SQLBaseStore(object):
|
||||||
def _parse_events_txn(self, txn, rows):
|
def _parse_events_txn(self, txn, rows):
|
||||||
events = [self._parse_event_from_row(r) for r in rows]
|
events = [self._parse_event_from_row(r) for r in rows]
|
||||||
|
|
||||||
sql = "SELECT * FROM events WHERE event_id = ?"
|
select_event_sql = "SELECT * FROM events WHERE event_id = ?"
|
||||||
|
|
||||||
for ev in events:
|
for ev in events:
|
||||||
signatures = self._get_event_origin_signatures_txn(
|
signatures = self._get_event_origin_signatures_txn(
|
||||||
|
@ -450,13 +450,12 @@ class SQLBaseStore(object):
|
||||||
k: encode_base64(v) for k, v in signatures.items()
|
k: encode_base64(v) for k, v in signatures.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_events = self._get_latest_events_in_room(txn, ev.room_id)
|
ev.prev_events = self._get_prev_events(txn, ev.event_id)
|
||||||
ev.prev_events = [(e_id, s,) for e_id, s, _ in prev_events]
|
|
||||||
|
|
||||||
if hasattr(ev, "prev_state"):
|
if hasattr(ev, "prev_state"):
|
||||||
# Load previous state_content.
|
# Load previous state_content.
|
||||||
# TODO: Should we be pulling this out above?
|
# TODO: Should we be pulling this out above?
|
||||||
cursor = txn.execute(sql, (ev.prev_state,))
|
cursor = txn.execute(select_event_sql, (ev.prev_state,))
|
||||||
prevs = self.cursor_to_dict(cursor)
|
prevs = self.cursor_to_dict(cursor)
|
||||||
if prevs:
|
if prevs:
|
||||||
prev = self._parse_event_from_row(prevs[0])
|
prev = self._parse_event_from_row(prevs[0])
|
||||||
|
@ -468,8 +467,8 @@ class SQLBaseStore(object):
|
||||||
|
|
||||||
if ev.redacted:
|
if ev.redacted:
|
||||||
# Get the redaction event.
|
# Get the redaction event.
|
||||||
sql = "SELECT * FROM events WHERE event_id = ?"
|
select_event_sql = "SELECT * FROM events WHERE event_id = ?"
|
||||||
txn.execute(sql, (ev.redacted,))
|
txn.execute(select_event_sql, (ev.redacted,))
|
||||||
|
|
||||||
del_evs = self._parse_events_txn(
|
del_evs = self._parse_events_txn(
|
||||||
txn, self.cursor_to_dict(txn)
|
txn, self.cursor_to_dict(txn)
|
||||||
|
|
|
@ -49,15 +49,6 @@ class EventFederationStore(SQLBaseStore):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_latest_events_in_room(self, txn, room_id):
|
def _get_latest_events_in_room(self, txn, room_id):
|
||||||
self._simple_select_onecol_txn(
|
|
||||||
txn,
|
|
||||||
table="event_forward_extremities",
|
|
||||||
keyvalues={
|
|
||||||
"room_id": room_id,
|
|
||||||
},
|
|
||||||
retcol="event_id",
|
|
||||||
)
|
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT e.event_id, e.depth FROM events as e "
|
"SELECT e.event_id, e.depth FROM events as e "
|
||||||
"INNER JOIN event_forward_extremities as f "
|
"INNER JOIN event_forward_extremities as f "
|
||||||
|
@ -78,6 +69,27 @@ class EventFederationStore(SQLBaseStore):
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def _get_prev_events(self, txn, event_id):
|
||||||
|
prev_ids = self._simple_select_onecol_txn(
|
||||||
|
txn,
|
||||||
|
table="event_edges",
|
||||||
|
keyvalues={
|
||||||
|
"event_id": event_id,
|
||||||
|
},
|
||||||
|
retcol="prev_event_id",
|
||||||
|
)
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for prev_event_id in prev_ids:
|
||||||
|
hashes = self._get_event_reference_hashes_txn(txn, prev_event_id)
|
||||||
|
prev_hashes = {
|
||||||
|
k: encode_base64(v) for k, v in hashes.items()
|
||||||
|
if k == "sha256"
|
||||||
|
}
|
||||||
|
results.append((event_id, prev_hashes))
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
def get_min_depth(self, room_id):
|
def get_min_depth(self, room_id):
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
"get_min_depth",
|
"get_min_depth",
|
||||||
|
|
Loading…
Reference in New Issue