0

Python Google App Engine に次のモデルがあります。

class UserAction(ndb.Model):

    author_gae_key = ndb.KeyProperty(indexed=True)
    target_gae_key = ndb.KeyProperty(indexed=True) # key of word, topic, etc.
    action_type = ndb.StringProperty(indexed=True) # select, like, dislike, wantToSee etc.
    recipients_keys = ndb.KeyProperty(repeated=True,indexed=True)

このクラスは一種のログであり、誰が何をクリックしたかなどの関係を照会できます。Receipients は、このアクションに関心を持つ可能性のある人々 (つまり、あなたの友人) のリストです。これは潜在的に長くなる可能性があり、あまり頻繁にシリアライズしたくありません。

特定の作成者が特定のターゲットに対して特定のアクションを実行したかどうかを示す次の関数があります。

def isActionDictMultipleTargets(action_type,author_gae_key,target_gae_keys_list):
    out_dict = {}
    if(target_gae_keys_list):
        actions = ndb.gql("SELECT * FROM UserAction WHERE author_gae_key = :1 AND action_type = :2 AND target_gae_key IN :3",author_gae_key,action_type,target_gae_keys_list)
        for an_action in actions:
            out_dict[an_action.target_gae_key.urlsafe()] = True
        false_keys = list(set(target_gae_keys_list)-set(out_dict.keys()))
        for a_key in false_keys:
            out_dict[a_key] = False
    return out_dict

今、私は .target_gae_key フィールドだけが必要です。等式フィルターがあるため、それに投影することはできません。

私は考えました:

  1. target_gae_key をエンティティの親キーとして設定し、キークエリを実行します。しかし、それはきれいではありません。また、author_gae_key に対しても同様のクエリが必要です。

  2. 最終的には、常にリストのサイズになるキーのみのクエリを実行し、クエリで何も見つからない場合は「空の」結果を返すのが最善です。それは存在しますか?

4

0 に答える 0