I'm finally upgrading from db
to ndb
(it is a much bigger headache than I anticipated...).
I used a lot of ReferenceProperty
and I've converted these to KeyProperty
. Now, every place where I used a ReferenceProperty
I need to add an explicit get because it was previously done for me automatically.
My question relates to whether I should restructure my code to make it more efficient. I have many methods that use a KeyProperty
and I need to do an explicit get()
. I'm wondering if I should change these methods so that I am passing the entity to them instead of using the KeyProperty
and a get()
.
Is the automatic memcaching for ndb
good enough that I don't need to restructure? Or should I restructure my code to avoid repeated gets of the same entity?
We are not looking at huge inefficiencies here. But for a single HTTP GET/POST I might be getting the same entity 3-5 times.
In your case the In-Context Cache will take over and save you the db calls:
Each request will get a new context.