'Store a room member in the database.'

def _store_room_members_txn(self, txn, events, backfilled):

    self._simple_insert_many_txn(txn, table='room_memberships', values=[{'event_id': event.event_id, 'user_id': event.state_key, 'sender': event.user_id, 'room_id': event.room_id, 'membership': event.membership, 'display_name': event.content.get('displayname', None), 'avatar_url': event.content.get('avatar_url', None)} for event in events])
    for event in events:
        txn.call_after(self._membership_stream_cache.entity_has_changed, event.state_key, event.internal_metadata.stream_ordering)
        txn.call_after(self.get_invited_rooms_for_user.invalidate, (event.state_key,))
        is_new_state = ((not backfilled) and ((not event.internal_metadata.is_outlier()) or event.internal_metadata.is_invite_from_remote()))
        is_mine = self.hs.is_mine_id(event.state_key)
        if (is_new_state and is_mine):
            if (event.membership == Membership.INVITE):
                self._simple_insert_txn(txn, table='local_invites', values={'event_id': event.event_id, 'invitee': event.state_key, 'inviter': event.sender, 'room_id': event.room_id, 'stream_id': event.internal_metadata.stream_ordering})
            else:
                sql = 'UPDATE    local_invites    SET    stream_id    =    ?,    replaced_by    =    ?    WHERE    room_id    =    ?    AND    invitee    =    ?    AND    locally_rejected    is    NULL    AND    replaced_by    is    NULL'
                txn.execute(sql, (event.internal_metadata.stream_ordering, event.event_id, event.room_id, event.state_key))
