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