mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Don't fetch redaction and rejection stuff for each event, so we can use index only scan
This commit is contained in:
parent
02590c3e1d
commit
6edff11a88
@ -918,10 +918,10 @@ class SQLBaseStore(object):
|
|||||||
start_time = update_counter("event_cache", start_time)
|
start_time = update_counter("event_cache", start_time)
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT e.internal_metadata, e.json, r.event_id, rej.reason "
|
"SELECT e.internal_metadata, e.json, r.redacts, rej.event_id "
|
||||||
"FROM event_json as e "
|
"FROM event_json as e "
|
||||||
|
"LEFT JOIN rejections as rej USING (event_id) "
|
||||||
"LEFT JOIN redactions as r ON e.event_id = r.redacts "
|
"LEFT JOIN redactions as r ON e.event_id = r.redacts "
|
||||||
"LEFT JOIN rejections as rej on rej.event_id = e.event_id "
|
|
||||||
"WHERE e.event_id = ? "
|
"WHERE e.event_id = ? "
|
||||||
"LIMIT 1 "
|
"LIMIT 1 "
|
||||||
)
|
)
|
||||||
@ -967,6 +967,14 @@ class SQLBaseStore(object):
|
|||||||
internal_metadata = json.loads(internal_metadata)
|
internal_metadata = json.loads(internal_metadata)
|
||||||
start_time = update_counter("decode_internal", start_time)
|
start_time = update_counter("decode_internal", start_time)
|
||||||
|
|
||||||
|
if rejected_reason:
|
||||||
|
rejected_reason = self._simple_select_one_onecol_txn(
|
||||||
|
txn,
|
||||||
|
table="rejections",
|
||||||
|
keyvalues={"event_id": rejected_reason},
|
||||||
|
retcol="reason",
|
||||||
|
)
|
||||||
|
|
||||||
ev = FrozenEvent(
|
ev = FrozenEvent(
|
||||||
d,
|
d,
|
||||||
internal_metadata_dict=internal_metadata,
|
internal_metadata_dict=internal_metadata,
|
||||||
@ -977,12 +985,19 @@ class SQLBaseStore(object):
|
|||||||
if check_redacted and redacted:
|
if check_redacted and redacted:
|
||||||
ev = prune_event(ev)
|
ev = prune_event(ev)
|
||||||
|
|
||||||
ev.unsigned["redacted_by"] = redacted
|
redaction_id = self._simple_select_one_onecol_txn(
|
||||||
|
txn,
|
||||||
|
table="redactions",
|
||||||
|
keyvalues={"redacts": ev.event_id},
|
||||||
|
retcol="event_id",
|
||||||
|
)
|
||||||
|
|
||||||
|
ev.unsigned["redacted_by"] = redaction_id
|
||||||
# Get the redaction event.
|
# Get the redaction event.
|
||||||
|
|
||||||
because = self._get_event_txn(
|
because = self._get_event_txn(
|
||||||
txn,
|
txn,
|
||||||
redacted,
|
redaction_id,
|
||||||
check_redacted=False
|
check_redacted=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,8 +85,10 @@ class StateStore(SQLBaseStore):
|
|||||||
|
|
||||||
def fetch_events(txn, events):
|
def fetch_events(txn, events):
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT e.internal_metadata, e.json "
|
"SELECT e.internal_metadata, e.json, r.redacts, rej.event_id "
|
||||||
" FROM event_json as e"
|
" FROM event_json as e"
|
||||||
|
" LEFT JOIN rejections as rej USING (event_id)"
|
||||||
|
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
|
||||||
" WHERE e.event_id IN (%s)"
|
" WHERE e.event_id IN (%s)"
|
||||||
) % (",".join(["?"]*len(events)),)
|
) % (",".join(["?"]*len(events)),)
|
||||||
|
|
||||||
@ -95,7 +97,8 @@ class StateStore(SQLBaseStore):
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
self._get_event_from_row_txn(
|
self._get_event_from_row_txn(
|
||||||
txn, row[0], row[1], None
|
txn, row[0], row[1], row[2],
|
||||||
|
rejected_reason=row[3],
|
||||||
)
|
)
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user