質問、類似、およびハッシュタグのエンティティがあります。また、LikeエンティティとQuestionエンティティの間には1対多の関係があります。私はGoogleのクラウドエンドポイントを使用しており、私の問題はここから始まります。私のリストメソッドでは、私はjsonとして20の質問を返します。しかし、質問の各質問オブジェクトについては、ユーザーが既に質問を好きであるかどうかをチェックし、質問に属する関連するハッシュタグも取得する必要があります。どのように私はキーだけバッチクエリで同じ操作を行うことができます。そうでない場合は、各オブジェクトに対してオブジェクト化されたアイテムのリストをロードする
ofy().load().type(Like.class)
.filter("questionRef =", questionKey)
.filter("accountRef =", accountKey).first().now();
を実行します。エンティティ
@Entity
@Cache
public class Like {
@Id
@Getter
protected Long id;
@Index
@Load
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
private Ref<Account> accountRef;
@Index
@Load
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
private Ref<Question> questionRef;
@Index
@Getter
protected Date createdAt;
Like() {
}
Like(Key<Account> accountKey) {
this.accountRef = Ref.create(accountKey);
this.createdAt = new Date();
}
}
ハッシュタグエンティティ
@Entity
@Cache
public class Hashtag implements Model<Hashtag> {
@Id
@Getter
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
private Long id;
@Index
@Load
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
private Ref<Question> questionRef;
@Index
@Getter
@Setter
private String text;
private Hashtag() {
}
private Hashtag(Builder builder) {
this.questionRef = builder.questionRef;
this.text = builder.text;
}
}
ありがとうございました。私はRIEで行くつもりです。私はリストのプロパティのために@Indexを使う?そして、おそらく5kの制限を超えてしまうので、私はタスクキューを持つ新しいエンティティを追加しなければならないと思います。 – krialix