Consider the following two alternatives.
A) Storing the key in the struct.
type Point struct {
Place *datastore.Key
Lat float64
Lon float64
}
Then fetching using the key:
place := new(Place)
if err := datastore.Get(c, k, point.Place); err != nil {
return err
}
B) Storing the id
type Point struct {
Place int64
Lat float64
Lon float64
}
Then fetching after creating the key.
k := datastore.NewKey(c, "Place", "", point.Place, nil)
place := new(Place)
if err := datastore.Get(c, k, place); err != nil {
return err
}
Storing the key instead of the id takes a bit more space. In order to see the tradeoff, it would be great to get a feeling for how much resources it takes to create a key. In other words, is it really cheap to create a key, or is it better to create it once and store it?
With a single key, it probably doesn't matter much, but let's say that I fetch a list of points, and for each point I want to retrieve the place (i.e. loop through the points to build an array of keys, and fetch them).
Edit: I am not thinking about allocating IDs or keys here, only using them (i.e. all points and places are already in the datastore, the question is just whether to store the id or the entire key).
Ex animo, Alexander Yngling