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

Commit 2aa37a4

Browse files
authored
Add state_key and rejection_reason to events (#11792)
... and start populating them for new events
1 parent b784299 commit 2aa37a4

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

changelog.d/11792.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Preparation for database schema simplifications: add `state_key` and `rejection_reason` columns to `events` table.

synapse/storage/databases/main/events.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,8 @@ def event_dict(event):
13891389
"received_ts",
13901390
"sender",
13911391
"contains_url",
1392+
"state_key",
1393+
"rejection_reason",
13921394
),
13931395
values=(
13941396
(
@@ -1405,8 +1407,10 @@ def event_dict(event):
14051407
self._clock.time_msec(),
14061408
event.sender,
14071409
"url" in event.content and isinstance(event.content["url"], str),
1410+
event.get_state_key(),
1411+
context.rejected or None,
14081412
)
1409-
for event, _ in events_and_contexts
1413+
for event, context in events_and_contexts
14101414
),
14111415
)
14121416

@@ -1456,6 +1460,7 @@ def _store_rejected_events_txn(self, txn, events_and_contexts):
14561460
for event, context in events_and_contexts:
14571461
if context.rejected:
14581462
# Insert the event_id into the rejections table
1463+
# (events.rejection_reason has already been done)
14591464
self._store_rejections_txn(txn, event.event_id, context.rejected)
14601465
to_remove.add(event)
14611466

synapse/storage/schema/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
5757
Changes in SCHEMA_VERSION = 68:
5858
- event_reference_hashes is no longer read.
59+
- `events` has `state_key` and `rejection_reason` columns, which are populated for
60+
new events.
5961
"""
6062

6163

6264
SCHEMA_COMPAT_VERSION = (
63-
# we have removed the public_room_list_stream table, so are now incompatible with
64-
# synapses wth SCHEMA_VERSION < 63.
65-
63
65+
# we now have `state_key` columns in both `events` and `state_events`, so
66+
# now incompatible with synapses wth SCHEMA_VERSION < 66.
67+
66
6668
)
6769
"""Limit on how far the synapse codebase can be rolled back without breaking db compat
6870
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright 2022 The Matrix.org Foundation C.I.C
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
-- Add new colums to the `events` table which will (one day) make the `state_events`
17+
-- and `rejections` tables redundant.
18+
19+
ALTER TABLE events
20+
-- if this event is a state event, its state key
21+
ADD COLUMN state_key TEXT DEFAULT NULL;
22+
23+
24+
ALTER TABLE events
25+
-- if this event was rejected, the reason it was rejected.
26+
ADD COLUMN rejection_reason TEXT DEFAULT NULL;

tests/storage/test_event_chain.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from synapse.api.constants import EventTypes
2020
from synapse.api.room_versions import RoomVersions
2121
from synapse.events import EventBase
22+
from synapse.events.snapshot import EventContext
2223
from synapse.rest import admin
2324
from synapse.rest.client import login, room
2425
from synapse.storage.databases.main.events import _LinkMap
@@ -391,7 +392,9 @@ def persist(
391392
def _persist(txn):
392393
# We need to persist the events to the events and state_events
393394
# tables.
394-
persist_events_store._store_event_txn(txn, [(e, {}) for e in events])
395+
persist_events_store._store_event_txn(
396+
txn, [(e, EventContext()) for e in events]
397+
)
395398

396399
# Actually call the function that calculates the auth chain stuff.
397400
persist_events_store._persist_event_auth_chain_txn(txn, events)

0 commit comments

Comments
 (0)