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

Commit 6138b12

Browse files
committed
Stop reading from event_edges.room_id.
1 parent b102118 commit 6138b12

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

changelog.d/12914.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_edges.room_id`.

synapse/storage/databases/main/event_federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ def _get_missing_events(
13181318

13191319
query = (
13201320
"SELECT prev_event_id FROM event_edges "
1321-
"WHERE room_id = ? AND event_id = ? AND is_state = ? "
1321+
"WHERE event_id = ? AND is_state = ? "
13221322
"LIMIT ?"
13231323
)
13241324

synapse/storage/databases/main/events_worker.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,18 @@ def is_event_next_to_gap_txn(txn: LoggingTransaction) -> bool:
19281928
LIMIT 1
19291929
"""
19301930

1931+
# We consider any forward extremity as the latest in the room and
1932+
# not a forward gap.
1933+
#
1934+
# To expand, even though there is technically a gap at the front of
1935+
# the room where the forward extremities are, we consider those the
1936+
# latest messages in the room so asking other homeservers for more
1937+
# is useless. The new latest messages will just be federated as
1938+
# usual.
1939+
txn.execute(forward_extremity_query, (event.room_id, event.event_id))
1940+
if txn.fetchone():
1941+
return False
1942+
19311943
# Check to see whether the event in question is already referenced
19321944
# by another event. If we don't see any edges, we're next to a
19331945
# forward gap.
@@ -1936,34 +1948,19 @@ def is_event_next_to_gap_txn(txn: LoggingTransaction) -> bool:
19361948
/* Check to make sure the event referencing our event in question is not rejected */
19371949
LEFT JOIN rejections ON event_edges.event_id = rejections.event_id
19381950
WHERE
1939-
event_edges.room_id = ?
1940-
AND event_edges.prev_event_id = ?
1951+
event_edges.prev_event_id = ?
19411952
/* It's not a valid edge if the event referencing our event in
19421953
* question is rejected.
19431954
*/
19441955
AND rejections.event_id IS NULL
19451956
LIMIT 1
19461957
"""
19471958

1948-
# We consider any forward extremity as the latest in the room and
1949-
# not a forward gap.
1950-
#
1951-
# To expand, even though there is technically a gap at the front of
1952-
# the room where the forward extremities are, we consider those the
1953-
# latest messages in the room so asking other homeservers for more
1954-
# is useless. The new latest messages will just be federated as
1955-
# usual.
1956-
txn.execute(forward_extremity_query, (event.room_id, event.event_id))
1957-
forward_extremities = txn.fetchall()
1958-
if len(forward_extremities):
1959-
return False
1960-
19611959
# If there are no forward edges to the event in question (another
19621960
# event hasn't referenced this event in their prev_events), then we
19631961
# assume there is a forward gap in the history.
1964-
txn.execute(forward_edge_query, (event.room_id, event.event_id))
1965-
forward_edges = txn.fetchall()
1966-
if not len(forward_edges):
1962+
txn.execute(forward_edge_query, (event.event_id,))
1963+
if not txn.fetchone():
19671964
return True
19681965

19691966
return False

synapse/storage/schema/__init__.py

Lines changed: 4 additions & 1 deletion
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 = 70 # remember to update the list below when updating
15+
SCHEMA_VERSION = 71 # 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
@@ -67,6 +67,9 @@
6767
6868
Changes in SCHEMA_VERSION = 70:
6969
- event_reference_hashes is no longer written to.
70+
71+
Changes in SCHEMA_VERSION = 71:
72+
- event_edges.room_id is no longer read from.
7073
"""
7174

7275

0 commit comments

Comments
 (0)