func lookupShelfDatastore(ctx ae.Context, user string) (shelf *data.Bookshelf, err error) { ancestor := ds.NewKey(ctx, data.KindBookshelf, user, 0, nil) query := ds.NewQuery(data.KindBookInfo).Ancestor(ancestor) targetMeta := new(data.BookMetaData) targetShelf := new(data.Bookshelf) switch err = ds.Get(ctx, ancestor, shelf); err { case nil: // all good case ds.ErrNoSuchEntity: targetShelf.Version = Latest default: return } it := query.Run(ctx) for _, err = it.Next(targetMeta); err == nil; _, err = it.Next(targetMeta) { targetShelf.Books = append(targetShelf.Books, *targetMeta) targetMeta = new(data.BookMetaData) } if err == ds.Done { err = nil shelf = targetShelf } ctx.Infof("Found %d items in datastore for key %v (error: %v)", len(targetShelf.Books), ancestor, err) return }
func getVolumeBulk(call *Call) (reply *data.LookupReply, err error) { var shelf *data.Bookshelf if shelf, err = persistence.LookupBookshelf(call.Context); err == nil { call.Context.Debugf("Bookshelf contains %d volumes", len(shelf.Books)) infos := shelf.Books for _, str := range call.Request.URL.Query()["search"] { matches := shelf.Search(str) infos = make([]data.BookMetaData, len(matches)) for i, ptr := range matches { infos[i] = *ptr } call.Context.Debugf("Filtered by \"%s\", down to %d entries: %v", str, len(infos), infos) } reply = &data.LookupReply{ Count: len(infos), BookInfos: shelf.Books, } } return }