Let’s say I want to create 2 new objects.
I want to do it in a transaction because I want to be sure that either both exist or none.
But I also need a big calculation so my question is where is best fitted for the calculation to be done. Inside the transaction scope? Or outside? (The key of a1 is irrelevant to the calculation so it does not need to be saved first)
@db.transactional()
def _register(self):
a1.put()
result = big_calculation_like_hashing(a1)
a2.prop = result
a2.put()
As always it depends. Since the calculation relies on
a2being complete it is probably best to be performed after thea2object is created, outside of the transaction. Unless of course these are all shared objects in some fashion, if that is the case you will need to do this within the context of the transaction to prevent data corruption.