'Update min_depth for each room
Args:
txn (twisted.enterprise.adbapi.Connection): db connection
events_and_contexts (list[(EventBase, EventContext)]): events
we are persisting
backfilled (bool): True if the events were backfilled'

def _update_room_depths_txn(self, txn, events_and_contexts, backfilled):

    depth_updates = {}
    for (event, context) in events_and_contexts:
        txn.call_after(self._invalidate_get_event_cache, event.event_id)
        if (not backfilled):
            txn.call_after(self._events_stream_cache.entity_has_changed, event.room_id, event.internal_metadata.stream_ordering)
        if ((not event.internal_metadata.is_outlier()) and (not context.rejected)):
            depth_updates[event.room_id] = max(event.depth, depth_updates.get(event.room_id, event.depth))
    for (room_id, depth) in depth_updates.iteritems():
        self._update_min_depth_for_room_txn(txn, room_id, depth)
