@defer.inlineCallbacks
    def _persist_auth_tree(self, auth_events, state, event):
        events_to_context = {}
        for e in itertools.chain(auth_events, state):
            ctx = yield self.state_handler.compute_event_context(
                e, outlier=True,
            )
            events_to_context[e.event_id] = ctx
            e.internal_metadata.outlier = True

        event_map = {
            e.event_id: e
            for e in auth_events
        }

        create_event = None
        for e in auth_events:
            if (e.type, e.state_key) == (EventTypes.Create, ""):
                create_event = e
                break

        for e in itertools.chain(auth_events, state, [event]):
            auth_for_e = {
                (event_map[e_id].type, event_map[e_id].state_key): event_map[e_id]
                for e_id, _ in e.auth_events
            }
            if create_event:
                auth_for_e[(EventTypes.Create, "")] = create_event

            try:
                self.auth.check(e, auth_events=auth_for_e)
            except SynapseError as err:
                # we may get SynapseErrors here as well as AuthErrors. For
                # instance, there are a couple of (ancient) events in some
                # rooms whose senders do not have the correct sigil; these
                # cause SynapseErrors in auth.check. We don't want to give up
                # the attempt to federate altogether in such cases.

                logger.warn(
                    "Rejecting %s because %s",
                    e.event_id, err.msg
                )

                if e == event:
                    raise
                events_to_context[e.event_id].rejected = RejectedReason.AUTH_ERROR

        yield self.store.persist_events(
            [
                (e, events_to_context[e.event_id])
                for e in itertools.chain(auth_events, state)
            ],
            is_new_state=False,
        )

        new_event_context = yield self.state_handler.compute_event_context(
            event, old_state=state, outlier=False,
        )

        event_stream_id, max_stream_id = yield self.store.persist_event(
            event, new_event_context,
            is_new_state=True,
            current_state=state,
        )

        defer.returnValue((event_stream_id, max_stream_id))
Return a query set in which the returned objects have been annotated
dataset/ETHPy150Open matrix-org/synapse/synapse/handlers/federation.py/FederationHandler._persist_auth_tree--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/query.py/QuerySet.annotate