在GAE中建立朋友关系 [英] Modeling a Friend relationship in GAE

查看:113
本文介绍了在GAE中建立朋友关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与GAE合作,并且有一个用户表。现在我想模拟用户之间的朋友关系。我想有3个属性 user1 user2 request_status ,但问题在于查询特定用户的朋友。由于GAE不允许过滤,因此我必须合并两个查询。显然这是非常低效的。这只是我的方法中的一个问题。
如果有人可以提出一个解决方案,让我可以跟踪所有的朋友请求以及友情,那么这将非常有用。

I am working with GAE and have a user table. Now I want to model friend relationships between users. I am thinking of having 3 properties user1, user2 and request_status, but the problem is in querying to find a particular user's friends. Since GAE does not allow OR filtering, I have to merge two queries. Clearly that is very inefficient. This is just one problem with my approach. If someone could suggest a solution that lets me keep track of all friend requests as well as the friendship, then that would be very helpful.

推荐答案

非规范化可以让你更有效地用一个查询找到用户的朋友。尝试在包含 的模型中存储另一个属性 users (a db.ListProperty user1 user2 。然后你可以简单地执行这样的查询来查找用户的朋友:

Denormalization will let you more efficiently find a user's friends with a single query. Try storing another property users (a db.ListProperty) in your model which contains both user1 and user2. Then you can simply execute a query like this to find a user's friends:

friendships = Friendship.all().filter('users =', user).fetch(...)

优点是您只需要一个单个查询(更快)。缺点是你将有一些额外的空间开销来存储用户属性和(自动)索引。

The advantage is that you only need a single query (faster). The disadvantage is that you will have a little extra space overhead to store the users property and the (automatic) index on it.

这篇关于在GAE中建立朋友关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆