'For a given room_id and stream_ordering, return the forward
extremeties of the room at that point in "time".
Throws a StoreError if we have since purged the index for
stream_orderings from that point.'

@cached(max_entries=5000, num_args=2)
def _get_forward_extremeties_for_room(self, room_id, stream_ordering):

    if (stream_ordering <= self.stream_ordering_month_ago):
        raise StoreError(400, 'stream_ordering    too    old')
    sql = '\n                                                                SELECT    event_id    FROM    stream_ordering_to_exterm\n                                                                INNER    JOIN    (\n                                                                                SELECT    room_id,    MAX(stream_ordering)    AS    stream_ordering\n                                                                                FROM    stream_ordering_to_exterm\n                                                                                WHERE    stream_ordering    <=    ?    GROUP    BY    room_id\n                                                                )    AS    rms    USING    (room_id,    stream_ordering)\n                                                                WHERE    room_id    =    ?\n                                '
    def get_forward_extremeties_for_room_txn(txn):
        txn.execute(sql, (stream_ordering, room_id))
        return [event_id for (event_id,) in txn]
    return self.runInteraction('get_forward_extremeties_for_room', get_forward_extremeties_for_room_txn)
