def PutAsync(entities, **kwargs): """ Asynchronously store one or more entities in the data store. This function is identical to :func:`server.db.Put`, except that it returns an asynchronous object. Call ``get_result()`` on the return value to block on the call and get the results. """ if isinstance(entities, Entity): entities._fixUnindexedProperties() elif isinstance(entities, List): for entity in entities: assert isinstance(entity, Entity) entity._fixUnindexedProperties() if conf["viur.db.caching"] > 0: if isinstance(entities, Entity): #Just one: if entities.is_saved(): #Its an update memcache.delete(str(entities.key()), namespace=__CacheKeyPrefix__, seconds=__cacheLockTime__) elif isinstance(entities, list): for entity in entities: assert isinstance(entity, Entity) if entity.is_saved(): #Its an update memcache.delete(str(entity.key()), namespace=__CacheKeyPrefix__, seconds=__cacheLockTime__) return (datastore.PutAsync(entities, **kwargs))
def delete_batch(key_slice): entities = datastore.Get(key_slice) #FIXME: We need to make sure the entity still matches the query! # entities = (x for x in entities if utils.entity_matches_query(x, self.select.gae_query)) to_delete = [] to_update = [] updated_keys = [] # Go through the entities for entity in entities: if entity is None: continue wipe_polymodel_from_entity(entity, self.table_to_delete) if not entity.get('class'): to_delete.append(entity) constraints.release(self.model, entity) else: to_update.append(entity) updated_keys.append(entity.key()) datastore.DeleteAsync([x.key() for x in to_delete]) datastore.PutAsync(to_update) caching.remove_entities_from_cache_by_key(updated_keys, self.namespace) return len(updated_keys)