584 |
584 |
585 result.extend(data) |
585 result.extend(data) |
586 offset = offset + chunk |
586 offset = offset + chunk |
587 |
587 |
588 return result |
588 return result |
|
589 |
|
590 def getBatchOfData(self, filter=None, order=None, next_key=None): |
|
591 """Returns one batch of entities |
|
592 |
|
593 Args: |
|
594 filter: a dict for the properties that the entities should have |
|
595 order: a list with the sort order |
|
596 next_key: a key for the first entity that should be returned |
|
597 |
|
598 Returns: |
|
599 A tuple: list of fetched entities and key value for the entity |
|
600 that should be fetched at first for the next batch |
|
601 """ |
|
602 |
|
603 query = self.getQueryForFields(filter=filter, order=order) |
|
604 |
|
605 if next_key is not None: |
|
606 query.filter('__key__ >=', next_key) |
|
607 |
|
608 entities = query.fetch(self.BATCH_SIZE + 1) |
|
609 |
|
610 next_key = None |
|
611 if len(entities) == self.BATCH_SIZE + 1: |
|
612 next_entity = entities.pop() |
|
613 next_key = next_entity.key() |
|
614 |
|
615 return entities, next_key |
|
616 |
589 # pylint: disable-msg=C0103 |
617 # pylint: disable-msg=C0103 |
590 def entityIterator(self, queryGen, batch_size = 100): |
618 def entityIterator(self, queryGen, batch_size=100): |
591 """Iterator that yields an entity in batches. |
619 """Iterator that yields an entity in batches. |
592 |
620 |
593 Args: |
621 Args: |
594 queryGen: should return a Query object |
622 queryGen: should return a Query object |
595 batchSize: how many entities to retrieve in one datastore call |
623 batchSize: how many entities to retrieve in one datastore call |