@@ -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
0 commit comments