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

Commit f1a0e7d

Browse files
committed
Merge remote-tracking branch 'origin/develop' into rav/new_events_columns
2 parents b8b56d0 + 9f2016e commit f1a0e7d

File tree

9 files changed

+52
-37
lines changed

9 files changed

+52
-37
lines changed

changelog.d/11794.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Preparation for database schema simplifications: stop reading from `event_reference_hashes`.

changelog.d/11795.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop unused table `public_room_list_stream`.

synapse/replication/slave/storage/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class SlavedEventStore(
5252
EventPushActionsWorkerStore,
5353
StreamWorkerStore,
5454
StateGroupWorkerStore,
55-
EventsWorkerStore,
5655
SignatureWorkerStore,
56+
EventsWorkerStore,
5757
UserErasureWorkerStore,
5858
RelationsWorkerStore,
5959
BaseSlavedStore,

synapse/storage/databases/main/event_federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, room_id: str):
6565
super().__init__("Unexpectedly no chain cover for events in %s" % (room_id,))
6666

6767

68-
class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBaseStore):
68+
class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBaseStore):
6969
def __init__(
7070
self,
7171
database: DatabasePool,

synapse/storage/databases/main/purge_events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def _purge_room_txn(self, txn, room_id: str) -> List[int]:
390390
"event_search",
391391
"events",
392392
"group_rooms",
393-
"public_room_list_stream",
394393
"receipts_graph",
395394
"receipts_linearized",
396395
"room_aliases",

synapse/storage/databases/main/signatures.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Dict, Iterable, List, Tuple
15+
from typing import Collection, Dict, List, Tuple
1616

1717
from unpaddedbase64 import encode_base64
1818

19-
from synapse.storage._base import SQLBaseStore
20-
from synapse.storage.types import Cursor
19+
from synapse.crypto.event_signing import compute_event_reference_hash
20+
from synapse.storage.databases.main.events_worker import (
21+
EventRedactBehaviour,
22+
EventsWorkerStore,
23+
)
2124
from synapse.util.caches.descriptors import cached, cachedList
2225

2326

24-
class SignatureWorkerStore(SQLBaseStore):
27+
class SignatureWorkerStore(EventsWorkerStore):
2528
@cached()
2629
def get_event_reference_hash(self, event_id):
2730
# This is a dummy function to allow get_event_reference_hashes
@@ -32,7 +35,7 @@ def get_event_reference_hash(self, event_id):
3235
cached_method_name="get_event_reference_hash", list_name="event_ids", num_args=1
3336
)
3437
async def get_event_reference_hashes(
35-
self, event_ids: Iterable[str]
38+
self, event_ids: Collection[str]
3639
) -> Dict[str, Dict[str, bytes]]:
3740
"""Get all hashes for given events.
3841
@@ -41,18 +44,27 @@ async def get_event_reference_hashes(
4144
4245
Returns:
4346
A mapping of event ID to a mapping of algorithm to hash.
47+
Returns an empty dict for a given event id if that event is unknown.
4448
"""
49+
events = await self.get_events(
50+
event_ids,
51+
redact_behaviour=EventRedactBehaviour.AS_IS,
52+
allow_rejected=True,
53+
)
4554

46-
def f(txn):
47-
return {
48-
event_id: self._get_event_reference_hashes_txn(txn, event_id)
49-
for event_id in event_ids
50-
}
55+
hashes: Dict[str, Dict[str, bytes]] = {}
56+
for event_id in event_ids:
57+
event = events.get(event_id)
58+
if event is None:
59+
hashes[event_id] = {}
60+
else:
61+
ref_alg, ref_hash_bytes = compute_event_reference_hash(event)
62+
hashes[event_id] = {ref_alg: ref_hash_bytes}
5163

52-
return await self.db_pool.runInteraction("get_event_reference_hashes", f)
64+
return hashes
5365

5466
async def add_event_hashes(
55-
self, event_ids: Iterable[str]
67+
self, event_ids: Collection[str]
5668
) -> List[Tuple[str, Dict[str, str]]]:
5769
"""
5870
@@ -70,24 +82,6 @@ async def add_event_hashes(
7082

7183
return list(encoded_hashes.items())
7284

73-
def _get_event_reference_hashes_txn(
74-
self, txn: Cursor, event_id: str
75-
) -> Dict[str, bytes]:
76-
"""Get all the hashes for a given PDU.
77-
Args:
78-
txn:
79-
event_id: Id for the Event.
80-
Returns:
81-
A mapping of algorithm -> hash.
82-
"""
83-
query = (
84-
"SELECT algorithm, hash"
85-
" FROM event_reference_hashes"
86-
" WHERE event_id = ?"
87-
)
88-
txn.execute(query, (event_id,))
89-
return {k: v for k, v in txn}
90-
9185

9286
class SignatureStore(SignatureWorkerStore):
9387
"""Persistence for event signatures and hashes"""

synapse/storage/schema/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
SCHEMA_VERSION = 67 # remember to update the list below when updating
15+
SCHEMA_VERSION = 68 # remember to update the list below when updating
1616
"""Represents the expectations made by the codebase about the database schema
1717
1818
This should be incremented whenever the codebase changes its requirements on the
@@ -53,12 +53,15 @@
5353
5454
Changes in SCHEMA_VERSION = 67:
5555
- state_events.prev_state is no longer written to.
56+
57+
Changes in SCHEMA_VERSION = 68:
58+
- event_reference_hashes is no longer read.
5659
"""
5760

5861

5962
SCHEMA_COMPAT_VERSION = (
60-
# the schema no longer support synapse versions with SCHEMA_VERSION < 66, because
61-
# there are multiple state_key columns.
63+
# we now have `state_key` columns in both `events` and `state_events`, so
64+
# now incompatible with synapses wth SCHEMA_VERSION < 66.
6265
66
6366
)
6467
"""Limit on how far the synapse codebase can be rolled back without breaking db compat
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
-- this table is unused as of Synapse 1.41
17+
DROP TABLE public_room_list_stream;
18+

tests/rest/admin/test_room.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,6 @@ def _block_room(self, room_id: str) -> None:
24682468
"event_search",
24692469
"events",
24702470
"group_rooms",
2471-
"public_room_list_stream",
24722471
"receipts_graph",
24732472
"receipts_linearized",
24742473
"room_aliases",

0 commit comments

Comments
 (0)