gpt4 book ai didi

java - 加入应用引擎的任何解决方案?

转载 作者:行者123 更新时间:2023-11-30 09:54:12 25 4
gpt4 key购买 nike

我有以下数据模型:

class StadiumOccupant {
String stadiumname;
String username;
}

class Friend {
String username;
String friendname;
}

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

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 不多,这就不起作用了。 App Engine 上有解决方案吗?我想不出一个表现出色的。

谢谢

-------- 一些样本数据--------

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

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

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

最佳答案

对于少量数据,您可以按照您的建议进行。对于大量数据,您无论如何都不会进行联接,即使您使用 SQL 数据库作为后端也是如此。

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

看我的回答here了解更多信息,包括 Facebook 工程师的帖子。

关于java - 加入应用引擎的任何解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3461469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com