

def _get_backfill_events(self, txn, room_id, event_list, limit):
    logger.debug('_get_backfill_events: %s, %s, %s', room_id, repr(event_list), limit)
    event_results = set()
    query = 'SELECT depth, prev_event_id FROM event_edges INNER JOIN events ON prev_event_id = events.event_id AND event_edges.room_id = events.room_id WHERE event_edges.room_id = ? AND event_edges.event_id = ? AND event_edges.is_state = ? LIMIT ?'
    queue = PriorityQueue()
    for event_id in event_list:
        depth = self._simple_select_one_onecol_txn(txn, table='events', keyvalues={
            'event_id': event_id,
        }, retcol='depth', allow_none=True)
        if depth:
            queue.put(((- depth), event_id))
    while ((not queue.empty()) and (len(event_results) < limit)):
        try:
            (_, event_id) = queue.get_nowait()
        except Empty:
            break
        if (event_id in event_results):
            continue
        event_results.add(event_id)
        txn.execute(query, (room_id, event_id, False, (limit - len(event_results))))
        for row in txn.fetchall():
            if (row[1] not in event_results):
                queue.put(((- row[0]), row[1]))
    return event_results

dataset/ETHPy150Open matrix-org/synapse/synapse/storage/event_federation.py EventFederationStore._get_backfill_events/original