'Update all the miscellaneous tables for new events
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_metadata_tables_txn(self, txn, events_and_contexts, backfilled):

    if (not events_and_contexts):
        return
    for (event, context) in events_and_contexts:
        if context.push_actions:
            self._set_push_actions_for_event_and_users_txn(txn, event, context.push_actions)
        if ((event.type == EventTypes.Redaction) and (event.redacts is not None)):
            self._remove_push_actions_for_event_id_txn(txn, event.room_id, event.redacts)
    self._simple_insert_many_txn(txn, table='event_auth', values=[{'event_id': event.event_id, 'room_id': event.room_id, 'auth_id': auth_id} for (event, _) in events_and_contexts for (auth_id, _) in event.auth_events if event.is_state()])
    self._handle_mult_prev_events(txn, events=[event for (event, _) in events_and_contexts])
    for (event, _) in events_and_contexts:
        if (event.type == EventTypes.Name):
            self._store_room_name_txn(txn, event)
        elif (event.type == EventTypes.Topic):
            self._store_room_topic_txn(txn, event)
        elif (event.type == EventTypes.Message):
            self._store_room_message_txn(txn, event)
        elif (event.type == EventTypes.Redaction):
            self._store_redaction(txn, event)
        elif (event.type == EventTypes.RoomHistoryVisibility):
            self._store_history_visibility_txn(txn, event)
        elif (event.type == EventTypes.GuestAccess):
            self._store_guest_access_txn(txn, event)
    self._store_room_members_txn(txn, [event for (event, _) in events_and_contexts if (event.type == EventTypes.Member)], backfilled=backfilled)
    self._store_event_reference_hashes_txn(txn, [event for (event, _) in events_and_contexts])
    state_events_and_contexts = [ec for ec in events_and_contexts if ec[0].is_state()]
    state_values = []
    for (event, context) in state_events_and_contexts:
        vals = {'event_id': event.event_id, 'room_id': event.room_id, 'type': event.type, 'state_key': event.state_key}
        if hasattr(event, 'replaces_state'):
            vals['prev_state'] = event.replaces_state
        state_values.append(vals)
    self._simple_insert_many_txn(txn, table='state_events', values=state_values)
    self._simple_insert_many_txn(txn, table='event_edges', values=[{'event_id': event.event_id, 'prev_event_id': prev_id, 'room_id': event.room_id, 'is_state': True} for (event, _) in state_events_and_contexts for (prev_id, _) in event.prev_state])
    self._add_to_cache(txn, events_and_contexts)
