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

标签 java google-app-engine bigtable

我有以下数据模型:

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/

相关文章:

python - 在同一事务上读取和修改 - Bigtable

java - 在 URL 中向用户显示键值是否存在任何安全问题?

java - RxJava 在网络关闭时取消订阅

java - 如何在java中的某些事件中取消选择Jlist项目

java - 将 JAXB 生成的类用于需要具有模式的整数的元素

java - EntityNotFoundException 的可能原因

java - 在模板文件中分配 freemarker 变量并读取 FreemarkerExceptionHandler 中的变量

java - 无法构建 Spring-boot-sample-gae(在 GAE 上部署 Spring Boot)

python - 使用App Engine Python处理/退回有关错误的传入电子邮件

database - 如何处理非常大的数据?