'Archives older notifications into event_push_summary. Returns whether
the archiving process has caught up or not.'

def _rotate_notifs_txn(self, txn):

    old_rotate_stream_ordering = self._simple_select_one_onecol_txn(txn, table='event_push_summary_stream_ordering', keyvalues={}, retcol='stream_ordering')
    txn.execute('\n                                                SELECT    stream_ordering    FROM    event_push_actions\n                                                WHERE    stream_ordering    >    ?\n                                                ORDER    BY    stream_ordering    ASC    LIMIT    1    OFFSET    50000\n                                ', (old_rotate_stream_ordering,))
    stream_row = txn.fetchone()
    if stream_row:
        (offset_stream_ordering,) = stream_row
        rotate_to_stream_ordering = min(self.stream_ordering_day_ago, offset_stream_ordering)
        caught_up = (offset_stream_ordering >= self.stream_ordering_day_ago)
    else:
        rotate_to_stream_ordering = self.stream_ordering_day_ago
        caught_up = True
    logger.info('Rotating    notifications    up    to:    %s', rotate_to_stream_ordering)
    self._rotate_notifs_before_txn(txn, rotate_to_stream_ordering)
    return caught_up
