Slide 34
Slide 34 text
͠Batch͕ͳ͔ͬͨΒ
// start fetching...
posts := make([]*Post, 0)
_, err = client.GetAll(ctx, client.NewQuery("Post").Order("Content"), &posts)
if err != nil {
panic(err)
}
// Let's batch get!
var commentKeys []datastore.Key
for _, post := range posts {
for _, commentID := range post.CommentIDs {
commentKeys = append(commentKeys, client.IDKey("Comment", commentID, nil))
}
}
comments := make([]*Comment, len(commentKeys))
err = client.GetMulti(ctx, commentKeys, comments)
if err != nil {
panic(err)
}
for _, post := range posts {
for _, commentID := range post.CommentIDs {
for idx, comment := range comments {
key := commentKeys[idx]
if commentID == key.ID() {
post.Comments = append(post.Comments, comment)
break
}
}
}
}
ErrNoSuchEntity͕
ࠞͬͨ͟Β͞ΒʹͭΒ͍…ʂ