def valid_subscribers(self, model, obj, using):
        """Calculate valid subscribers (connections) for obj."""
        col_user_ids = {}
        col_connection_ids = collections.defaultdict(set)
        for sub in Subscription.objects.filter(
                collections__model_name=model_name(model),
        ).prefetch_related('collections'):
            pub = self.get_pub_by_name(sub.publication)
            try:
                queries = list(pub.user_queries(sub.user, *sub.params))
            except Exception:
                queries = []
            for qs, col in (
                    self.qs_and_collection(qs)
                    for qs
                    in queries
            ):
                # check if obj is an instance of the model for the queryset
                if qs.model is not model:
                    continue  # wrong model on queryset

                # check if obj is included in this subscription
                if not qs.filter(pk=obj.pk).exists():
                    continue  # subscription doesn't include this obj

                # filter qs using user_rel paths on collection
                # retreieve list of allowed users via colleciton
                try:
                    user_ids = col_user_ids[col.__class__]
                except __HOLE__:
                    user_ids = col_user_ids[col.__class__] = \
                        col.user_ids_for_object(obj)

                # check if user is in permitted list of users
                if user_ids is None:
                    pass  # unrestricted collection, anyone permitted to see.
                elif sub.user_id not in user_ids:
                    continue  # not for this user

                col_connection_ids[col].add(sub.connection_id)

        # result is {colleciton: set([connection_id])}
        return col_connection_ids
dataset/ETHPy150Open django-ddp/django-ddp/dddp/api.py/DDP.valid_subscribers