I have the following model in 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)
This class is kind of a log, and lets me query relationships such as who clicked on what. Receipients is a list, for people potentially interested by this action (i.e. your friends). This could potentially be long, and I'd rather not serialize it too often.
I have the following function, that tells me if a certain author did a certain action on a certain target:
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
Now I only need the .target_gae_key field, by I cannot project on it because there is an equality filter.
I thought of:
setting target_gae_key as a parent key of the entity, and doing a key query. But it's not pretty, and I also want a similar query on author_gae_key.
in the end, the best would be to do a key only query with an results that would always be the size of the list, with "empty" results when the query doesn't find anything. Does that exist?