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

Commit 8568cd0

Browse files
committed
Stop reading from event_edges.room_id.
1 parent b102118 commit 8568cd0

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,19 @@ 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+
forward_extremities = txn.fetchall()
1941+
if len(forward_extremities):
1942+
return False
1943+
19311944
# Check to see whether the event in question is already referenced
19321945
# by another event. If we don't see any edges, we're next to a
19331946
# forward gap.
@@ -1936,32 +1949,18 @@ def is_event_next_to_gap_txn(txn: LoggingTransaction) -> bool:
19361949
/* Check to make sure the event referencing our event in question is not rejected */
19371950
LEFT JOIN rejections ON event_edges.event_id = rejections.event_id
19381951
WHERE
1939-
event_edges.room_id = ?
1940-
AND event_edges.prev_event_id = ?
1952+
event_edges.prev_event_id = ?
19411953
/* It's not a valid edge if the event referencing our event in
19421954
* question is rejected.
19431955
*/
19441956
AND rejections.event_id IS NULL
19451957
LIMIT 1
19461958
"""
19471959

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-
19611960
# If there are no forward edges to the event in question (another
19621961
# event hasn't referenced this event in their prev_events), then we
19631962
# assume there is a forward gap in the history.
1964-
txn.execute(forward_edge_query, (event.room_id, event.event_id))
1963+
txn.execute(forward_edge_query, (event.event_id,))
19651964
forward_edges = txn.fetchall()
19661965
if not len(forward_edges):
19671966
return True

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)