mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-14 07:10:48 +00:00
Stop reading from the rejections and state_events tables
This commit is contained in:
@@ -2426,9 +2426,8 @@ class EventFederationStore(EventFederationWorkerStore):
|
||||
DELETE FROM event_auth
|
||||
WHERE event_id IN (
|
||||
SELECT event_id FROM events
|
||||
LEFT JOIN state_events AS se USING (room_id, event_id)
|
||||
WHERE ? <= stream_ordering AND stream_ordering < ?
|
||||
AND se.state_key IS null
|
||||
AND state_key IS NULL
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
@@ -951,11 +951,10 @@ class PersistEventsStore:
|
||||
SELECT prev_event_id, internal_metadata
|
||||
FROM event_edges
|
||||
INNER JOIN events USING (event_id)
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
LEFT JOIN event_json USING (event_id)
|
||||
WHERE
|
||||
NOT events.outlier
|
||||
AND rejections.event_id IS NULL
|
||||
AND events.rejection_reason IS NULL
|
||||
AND
|
||||
"""
|
||||
|
||||
@@ -1008,10 +1007,9 @@ class PersistEventsStore:
|
||||
sql = """
|
||||
SELECT
|
||||
event_id, prev_event_id, internal_metadata,
|
||||
rejections.event_id IS NOT NULL
|
||||
events.rejection_reason IS NOT NULL
|
||||
FROM event_edges
|
||||
INNER JOIN events USING (event_id)
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
LEFT JOIN event_json USING (event_id)
|
||||
WHERE
|
||||
NOT events.outlier
|
||||
@@ -1057,8 +1055,9 @@ class PersistEventsStore:
|
||||
"""Insert some number of room events into the necessary database tables.
|
||||
|
||||
Rejected events are only inserted into the events table, the events_json table,
|
||||
and the rejections table. Things reading from those table will need to check
|
||||
whether the event was rejected.
|
||||
and the (deprecated) rejections table.
|
||||
Things reading from those tables will need to check
|
||||
`events.rejection_reason` to see whether the event was rejected.
|
||||
|
||||
Assumes that we are only persisting events for one room at a time.
|
||||
|
||||
@@ -1353,11 +1352,10 @@ class PersistEventsStore:
|
||||
# fetch their auth event info.
|
||||
while missing_auth_chains:
|
||||
sql = """
|
||||
SELECT event_id, events.type, se.state_key, chain_id, sequence_number
|
||||
SELECT event_id, events.type, events.state_key, chain_id, sequence_number
|
||||
FROM events
|
||||
INNER JOIN state_events AS se USING (event_id)
|
||||
LEFT JOIN event_auth_chains USING (event_id)
|
||||
WHERE
|
||||
WHERE events.state_key IS NOT NULL AND
|
||||
"""
|
||||
clause, args = make_in_list_sql_clause(
|
||||
txn.database_engine,
|
||||
@@ -3070,9 +3068,8 @@ class PersistEventsStore:
|
||||
"SELECT "
|
||||
" e.event_id as event_id, "
|
||||
" r.redacts as redacts,"
|
||||
" rej.event_id as rejects "
|
||||
" e.rejection_reason IS NOT NULL as rejected "
|
||||
" FROM events as e"
|
||||
" LEFT JOIN rejections as rej USING (event_id)"
|
||||
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
|
||||
" WHERE "
|
||||
)
|
||||
@@ -3082,9 +3079,9 @@ class PersistEventsStore:
|
||||
)
|
||||
|
||||
txn.execute(sql + clause, args)
|
||||
for event_id, redacts, rejects in txn:
|
||||
for event_id, redacts, rejected in txn:
|
||||
event = ev_map[event_id]
|
||||
if not rejects and not redacts:
|
||||
if not rejected and not redacts:
|
||||
to_prefill.append(EventCacheEntry(event=event, redacted_event=None))
|
||||
|
||||
async def external_prefill() -> None:
|
||||
|
||||
@@ -556,7 +556,7 @@ class EventsBackgroundUpdatesStore(
|
||||
# rejection status.
|
||||
txn.execute(
|
||||
"""SELECT prev_event_id, event_id, internal_metadata,
|
||||
rejections.event_id IS NOT NULL, events.outlier
|
||||
events.rejection_reason IS NOT NULL, events.outlier
|
||||
FROM (
|
||||
SELECT event_id AS prev_event_id
|
||||
FROM _extremities_to_check
|
||||
@@ -565,7 +565,6 @@ class EventsBackgroundUpdatesStore(
|
||||
LEFT JOIN event_edges USING (prev_event_id)
|
||||
LEFT JOIN events USING (event_id)
|
||||
LEFT JOIN event_json USING (event_id)
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
""",
|
||||
(batch_size,),
|
||||
)
|
||||
@@ -600,11 +599,10 @@ class EventsBackgroundUpdatesStore(
|
||||
soft_failed_events_to_lookup = set(to_defer)
|
||||
|
||||
sql = """SELECT prev_event_id, event_id, internal_metadata,
|
||||
rejections.event_id IS NOT NULL
|
||||
events.rejection_reason IS NOT NULL
|
||||
FROM event_edges
|
||||
INNER JOIN events USING (event_id)
|
||||
INNER JOIN event_json USING (event_id)
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE
|
||||
NOT events.outlier
|
||||
AND
|
||||
@@ -1028,14 +1026,14 @@ class EventsBackgroundUpdatesStore(
|
||||
|
||||
sql = """
|
||||
SELECT
|
||||
event_id, state_events.type, state_events.state_key,
|
||||
event_id, events.type, events.state_key,
|
||||
topological_ordering, stream_ordering,
|
||||
events.room_id
|
||||
FROM events
|
||||
INNER JOIN state_events USING (event_id)
|
||||
LEFT JOIN event_auth_chains USING (event_id)
|
||||
LEFT JOIN event_auth_chain_to_calculate USING (event_id)
|
||||
WHERE event_auth_chains.event_id IS NULL
|
||||
WHERE events.state_key IS NOT NULL
|
||||
AND event_auth_chains.event_id IS NULL
|
||||
AND event_auth_chain_to_calculate.event_id IS NULL
|
||||
AND %(tuple_cmp)s
|
||||
%(extra)s
|
||||
|
||||
@@ -1620,12 +1620,11 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
ej.json,
|
||||
ej.format_version,
|
||||
r.room_version,
|
||||
rej.reason,
|
||||
e.rejection_reason,
|
||||
e.outlier
|
||||
FROM events AS e
|
||||
JOIN event_json AS ej USING (event_id)
|
||||
LEFT JOIN rooms r ON r.room_id = e.room_id
|
||||
LEFT JOIN rejections as rej USING (event_id)
|
||||
WHERE """
|
||||
|
||||
clause, args = make_in_list_sql_clause(
|
||||
@@ -1963,14 +1962,12 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
) -> list[tuple[int, str, str, str, str, str, str, str, bool, bool]]:
|
||||
sql = (
|
||||
"SELECT e.stream_ordering, e.event_id, e.room_id, e.type,"
|
||||
" se.state_key, redacts, relates_to_id, membership, rejections.reason IS NOT NULL,"
|
||||
" e.state_key, redacts, relates_to_id, membership, e.rejection_reason IS NOT NULL,"
|
||||
" e.outlier"
|
||||
" FROM events AS e"
|
||||
" LEFT JOIN redactions USING (event_id)"
|
||||
" LEFT JOIN state_events AS se USING (event_id)"
|
||||
" LEFT JOIN event_relations USING (event_id)"
|
||||
" LEFT JOIN room_memberships USING (event_id)"
|
||||
" LEFT JOIN rejections USING (event_id)"
|
||||
" WHERE ? < stream_ordering AND stream_ordering <= ?"
|
||||
" AND instance_name = ?"
|
||||
" ORDER BY stream_ordering ASC"
|
||||
@@ -2006,17 +2003,15 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
) -> list[tuple[int, str, str, str, str, str, str, str, bool, bool]]:
|
||||
sql = (
|
||||
"SELECT out.event_stream_ordering, e.event_id, e.room_id, e.type,"
|
||||
" se.state_key, redacts, relates_to_id, membership, rejections.reason IS NOT NULL,"
|
||||
" e.state_key, redacts, relates_to_id, membership, e.rejection_reason IS NOT NULL,"
|
||||
" e.outlier"
|
||||
" FROM events AS e"
|
||||
# NB: the next line (inner join) is what makes this query different from
|
||||
# get_all_new_forward_event_rows.
|
||||
" INNER JOIN ex_outlier_stream AS out USING (event_id)"
|
||||
" LEFT JOIN redactions USING (event_id)"
|
||||
" LEFT JOIN state_events AS se USING (event_id)"
|
||||
" LEFT JOIN event_relations USING (event_id)"
|
||||
" LEFT JOIN room_memberships USING (event_id)"
|
||||
" LEFT JOIN rejections USING (event_id)"
|
||||
" WHERE ? < out.event_stream_ordering"
|
||||
" AND out.event_stream_ordering <= ?"
|
||||
" AND out.instance_name = ?"
|
||||
@@ -2068,10 +2063,9 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
) -> tuple[list[tuple[int, tuple[str, str, str, str, str, str]]], int, bool]:
|
||||
sql = (
|
||||
"SELECT -e.stream_ordering, e.event_id, e.room_id, e.type,"
|
||||
" se.state_key, redacts, relates_to_id"
|
||||
" e.state_key, redacts, relates_to_id"
|
||||
" FROM events AS e"
|
||||
" LEFT JOIN redactions USING (event_id)"
|
||||
" LEFT JOIN state_events AS se USING (event_id)"
|
||||
" LEFT JOIN event_relations USING (event_id)"
|
||||
" WHERE ? > stream_ordering AND stream_ordering >= ?"
|
||||
" AND instance_name = ?"
|
||||
@@ -2098,11 +2092,10 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
|
||||
sql = (
|
||||
"SELECT -event_stream_ordering, e.event_id, e.room_id, e.type,"
|
||||
" se.state_key, redacts, relates_to_id"
|
||||
" e.state_key, redacts, relates_to_id"
|
||||
" FROM events AS e"
|
||||
" INNER JOIN ex_outlier_stream AS out USING (event_id)"
|
||||
" LEFT JOIN redactions USING (event_id)"
|
||||
" LEFT JOIN state_events AS se USING (event_id)"
|
||||
" LEFT JOIN event_relations USING (event_id)"
|
||||
" WHERE ? > event_stream_ordering"
|
||||
" AND event_stream_ordering >= ?"
|
||||
@@ -2476,13 +2469,13 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
forward_edge_query = """
|
||||
SELECT 1 FROM event_edges
|
||||
/* Check to make sure the event referencing our event in question is not rejected */
|
||||
LEFT JOIN rejections ON event_edges.event_id = rejections.event_id
|
||||
LEFT JOIN events ON event_edges.event_id = events.event_id
|
||||
WHERE
|
||||
event_edges.prev_event_id = ?
|
||||
/* It's not a valid edge if the event referencing our event in
|
||||
* question is rejected.
|
||||
*/
|
||||
AND rejections.event_id IS NULL
|
||||
AND events.rejection_reason IS NULL
|
||||
LIMIT 1
|
||||
"""
|
||||
|
||||
@@ -2531,7 +2524,6 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
|
||||
sql_template = f"""
|
||||
SELECT event_id FROM events
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE
|
||||
room_id = ?
|
||||
AND origin_server_ts {comparison_operator} ?
|
||||
@@ -2544,7 +2536,7 @@ class EventsWorkerStore(SQLBaseStore):
|
||||
*/
|
||||
AND NOT outlier
|
||||
/* Make sure event is not rejected */
|
||||
AND rejections.event_id IS NULL
|
||||
AND rejection_reason IS NULL
|
||||
/**
|
||||
* First sort by the message timestamp. If the message timestamps are the
|
||||
* same, we want the message that logically comes "next" (before/after
|
||||
|
||||
@@ -207,7 +207,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
|
||||
|
||||
logger.info("[purge] looking for events to delete")
|
||||
|
||||
should_delete_expr = "state_events.state_key IS NULL"
|
||||
should_delete_expr = "e.state_key IS NULL"
|
||||
should_delete_params: tuple[Any, ...] = ()
|
||||
if not delete_local_events:
|
||||
should_delete_expr += " AND sender NOT LIKE ?"
|
||||
@@ -222,7 +222,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
|
||||
txn.execute(
|
||||
"INSERT INTO events_to_purge"
|
||||
" SELECT event_id, %s"
|
||||
" FROM events AS e LEFT JOIN state_events USING (event_id)"
|
||||
" FROM events AS e"
|
||||
" WHERE (NOT outlier OR (%s)) AND e.room_id = ? AND topological_ordering < ?"
|
||||
% (should_delete_expr, should_delete_expr),
|
||||
should_delete_params,
|
||||
|
||||
@@ -29,8 +29,8 @@ logger = logging.getLogger(__name__)
|
||||
class RejectionsStore(SQLBaseStore):
|
||||
async def get_rejection_reason(self, event_id: str) -> str | None:
|
||||
return await self.db_pool.simple_select_one_onecol(
|
||||
table="rejections",
|
||||
retcol="reason",
|
||||
table="events",
|
||||
retcol="rejection_reason",
|
||||
keyvalues={"event_id": event_id},
|
||||
allow_none=True,
|
||||
desc="get_rejection_reason",
|
||||
|
||||
@@ -201,10 +201,8 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
SELECT e.event_id, e.room_id, e.type, se.state_key, r.reason
|
||||
SELECT e.event_id, e.room_id, e.type, e.state_key, e.rejection_reason
|
||||
FROM events AS e
|
||||
LEFT JOIN state_events se USING (event_id)
|
||||
LEFT JOIN rejections r USING (event_id)
|
||||
WHERE {clause}
|
||||
"""
|
||||
|
||||
|
||||
@@ -1479,11 +1479,10 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||
sql = """
|
||||
SELECT stream_ordering, topological_ordering, event_id
|
||||
FROM events
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE room_id = ?
|
||||
AND stream_ordering <= ?
|
||||
AND NOT outlier
|
||||
AND rejections.event_id IS NULL
|
||||
AND rejection_reason IS NULL
|
||||
ORDER BY stream_ordering DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
@@ -1553,11 +1552,10 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||
sql = f"""
|
||||
SELECT event_id, stream_ordering, instance_name
|
||||
FROM events
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE room_id = ?
|
||||
{event_type_clause}
|
||||
AND NOT outlier
|
||||
AND rejections.event_id IS NULL
|
||||
AND rejection_reason IS NULL
|
||||
ORDER BY stream_ordering DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
@@ -1637,24 +1635,22 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||
SELECT * FROM (
|
||||
SELECT instance_name, stream_ordering, topological_ordering, event_id
|
||||
FROM events
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE room_id = ?
|
||||
%s
|
||||
AND ? < stream_ordering AND stream_ordering <= ?
|
||||
AND NOT outlier
|
||||
AND rejections.event_id IS NULL
|
||||
AND rejection_reason IS NULL
|
||||
ORDER BY stream_ordering DESC
|
||||
) AS a
|
||||
UNION ALL
|
||||
SELECT * FROM (
|
||||
SELECT instance_name, stream_ordering, topological_ordering, event_id
|
||||
FROM events
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE room_id = ?
|
||||
%s
|
||||
AND stream_ordering <= ?
|
||||
AND NOT outlier
|
||||
AND rejections.event_id IS NULL
|
||||
AND rejection_reason IS NULL
|
||||
ORDER BY stream_ordering DESC
|
||||
LIMIT 1
|
||||
) AS b
|
||||
@@ -1782,7 +1778,6 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||
sql = f"""
|
||||
SELECT room_id, (
|
||||
SELECT stream_ordering FROM events AS e
|
||||
LEFT JOIN rejections USING (event_id)
|
||||
WHERE e.room_id = r.room_id
|
||||
AND e.stream_ordering <= ?
|
||||
AND NOT outlier
|
||||
|
||||
Reference in New Issue
Block a user