Exemplo n.º 1
0
    def QueryFollowerIds(cls,
                         client,
                         viewpoint_id,
                         callback,
                         excl_start_key=None,
                         limit=None):
        """Query followers belonging to the viewpoint (up to 'limit' total) for
    the specified 'viewpoint_id'. The query is for followers starting with
    (but excluding) 'excl_start_key'. The callback is invoked with an array
    of follower user ids and the last queried key.
    """
        def _OnQueryFollowerKeys(follower_keys):
            follower_ids = [key.hash_key for key in follower_keys]
            last_key = follower_ids[-1] if len(follower_ids) > 0 else None

            callback((follower_ids, last_key))

        # Query the viewpoint_id secondary index with excl_start_key & limit.
        query_expr = ('follower.viewpoint_id={id}', {'id': viewpoint_id})
        start_index_key = db_client.DBKey(
            excl_start_key,
            viewpoint_id) if excl_start_key is not None else None
        Follower.IndexQueryKeys(client,
                                query_expr,
                                callback=_OnQueryFollowerKeys,
                                start_index_key=start_index_key,
                                limit=limit)