加入应用程序引擎有什么解决方案吗?

发布于 2024-09-14 02:46:36 字数 979 浏览 4 评论 0原文

我有以下数据模型:

class StadiumOccupant {
  String stadiumname;
  String username;
}

class Friend {
  String username;
  String friendname;
}

我想找到体育场内所有也是我朋友的用户。我可以这样做:

List<String> friendsAtStadium;
String stadiumId = 'xyz';

List<Friend> friends = select from Friend where username = 'me';
for (Friend friend : friends) {
  List<StadiumOccupant> friendAtStadium = 
    select from StadiumOccupant where 
    stadiumname = stadiumId and
    username = friend.friendname;
  friendsAtStadium.addAll(friendAtStadium);
}

这可以处理很少数量的对象。一旦用户拥有多个朋友,这就不起作用了。应用程序引擎上有解决方案吗?我想不出表现良好的一个。

谢谢

-------- 一些示例数据 --------

Friend { john, tim }
Friend { john, mary }
Friend { mary, frank }

StadiumOccupant { abc, tim }
StadiumOccupant { abc, frank }
StadiumOccupant { abc, kim }

所以如果我是用户“john”,我的朋友是:{ tim,mary }。 如果我要使用 Stadiumname='abc' 运行体育场查询,我应该返回 { tim }。

I have the following data model:

class StadiumOccupant {
  String stadiumname;
  String username;
}

class Friend {
  String username;
  String friendname;
}

I want to find all users at a stadium that are also my friends. I can do that like this:

List<String> friendsAtStadium;
String stadiumId = 'xyz';

List<Friend> friends = select from Friend where username = 'me';
for (Friend friend : friends) {
  List<StadiumOccupant> friendAtStadium = 
    select from StadiumOccupant where 
    stadiumname = stadiumId and
    username = friend.friendname;
  friendsAtStadium.addAll(friendAtStadium);
}

This can work with a very small number of objects. As soon as a user has more than a handful of friends, this won't work. Is there a solution to this on app engine? I can't think of one that performs well.

Thanks

-------- Some sample data --------

Friend { john, tim }
Friend { john, mary }
Friend { mary, frank }

StadiumOccupant { abc, tim }
StadiumOccupant { abc, frank }
StadiumOccupant { abc, kim }

so if I am user 'john', my friends are: { tim, mary }.
if I were to run the stadium query with stadiumname='abc' I should get back { tim }.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2024-09-21 02:46:36

对于少量数据,您可以按照您的建议进行操作。对于大量数据,即使您在后端使用 SQL 数据库,您也不会执行联接。

您的问题几乎是典型的社交网络数据问题。最有可能的是,您需要对数据进行非规范化,并在用户更新状态时将信息“推送”到所有用户的朋友列表,或者可能像您上面所做的那样提取信息。最佳解决方案取决于数据的形状以及您想要优化的查询类型 - 检索或更新。

请参阅我的回答此处了解更多信息,包括 Facebook 工程师的帖子。

For small amounts of data, you can do what you propose. For larger amounts of data, you wouldn't be doing a join anyway, even if you were using a SQL database for your backend.

Your problem is pretty much the typical social networking data problem. Most likely, you will want to denormalize your data, and "push" information to all of a user's friend list whenever they update their status, or possibly pull it as you are doing above. The best solution depends on the shape of your data and what kinds of queries you want to optimize for - retrieval or updates.

See my answer here for more info, including a post by a facebook engineer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文