def txn(): read_state_list = ndb.get_multi(read_state_keys) to_put = [] for key, read_state in zip(read_state_keys, read_state_list): next_read_sequence = topic_dict[key.id()] if read_state is None: read_state = models.ReadState(key=key) read_state.last_read_sequence = next_read_sequence else: read_state.last_read_sequence = max( read_state.last_read_sequence, next_read_sequence) to_put.append(read_state) ndb.put_multi(to_put)
def txn(): shard_record = models.Shard.get_by_id(shard) # TODO(bslatkin): Just drop this task entirely if the shard cannot # be found. Could happen for old shards that were cleaned up. assert shard_record # One of the tasks in this batch has a topic assignment. Apply it here. if new_topic: logging.debug('Changing topic from %r to %r', shard_record.current_topic, new_topic) shard_record.current_topic = new_topic shard_record.topic_change_time = now new_sequence_numbers = list(xrange( shard_record.sequence_number, shard_record.sequence_number + len(unapplied_receipts))) shard_record.sequence_number += max(1, len(unapplied_receipts)) # Write post references that point at the newly sequenced posts. to_put = [shard_record] for receipt, sequence in zip(unapplied_receipts, new_sequence_numbers): to_put.append(models.PostReference( id=sequence, parent=shard_record.key, post_id=receipt.post_id)) # Update the receipt entity here; it will be written outside this # transaction, since these receipts may span multiple entity # groups. receipt.sequence = sequence # Enqueue replica posts transactionally, to make sure everything # definitely will get copied over to the replica shard. if shard_record.current_topic: enqueue_post_task(shard_record.current_topic, unapplied_post_ids) ndb.put_multi(to_put) return shard_record, new_sequence_numbers
def put_new(people): keys = ndb.put_multi(people, use_cache=False, use_memcache=False)