I'm having some strange issues with datastore queries on golang. The query executes fine however when it comes to pulling the total (cli.Count()) it fails every time consistently by timing out. Can someone explain if I'm doing something wrong or if there is a correct way to do this? The strange part is just that it fails on a query count and I don't get why, I've tried to create a NewQuery and intializing a new client too but neither works.
// GetListByID provides an iterative list of all items filtered by ID.
func GetListByID(theID, limit, offset int) ([]Item, int, error) {
var itemList []Item
cli, ctx, err := getClient()
if err != nil {
return itemList, 0, err
}
if limit <= 0 {
limit = 20
}
q := datastore.NewQuery("SomeKind").Filter("MasterID = ", theID)
ql := q.Limit(limit).Offset(offset)
_, err = cli.GetAll(ctx, ql, &itemList)
if err != nil {
return itemList, 0, err
}
if len(itemList) < limit && offset == 0 {
return itemList, len(itemList), nil
}
total, err := cli.Count(ctx, q)
return itemList, total, err
}
Please note that it does not run on appengine. It runs on instances in AWS and in datacenter. (Don't ask)