app/soc/logic/models/base.py
changeset 2989 4ab340430bfa
parent 2980 cbfd8e12527a
child 2992 c860b26481be
equal deleted inserted replaced
2988:e11f934e6063 2989:4ab340430bfa
   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 
   589 
   590   def getBatchOfData(self, filter=None, order=None, next_key=None):
   590   def getBatchOfData(self, filter=None, order=None, next_key=None, batch_size=10):
   591     """Returns one batch of entities
   591     """Returns one batch of entities
   592 
   592 
   593     Args:
   593     Args:
   594       filter: a dict for the properties that the entities should have
   594       filter: a dict for the properties that the entities should have
   595       order: a list with the sort order
   595       order: a list with the sort order
   596       next_key: a key for the first entity that should be returned
   596       next_key: a key for the first entity that should be returned
       
   597       batch_size: the maximum amount of entities that should be fetched
   597 
   598 
   598     Returns:
   599     Returns:
   599       A tuple: list of fetched entities and key value for the entity
   600       A tuple: list of fetched entities and key value for the entity
   600       that should be fetched at first for the next batch
   601       that should be fetched at first for the next batch
   601     """
   602     """
   602 
   603 
       
   604     batch_size = min(999, batch_size)
       
   605 
   603     query = self.getQueryForFields(filter=filter, order=order)
   606     query = self.getQueryForFields(filter=filter, order=order)
   604 
   607 
   605     if next_key is not None:
   608     if next_key is not None:
   606       query.filter('__key__ >=', next_key)
   609       query.filter('__key__ >=', next_key)
   607 
   610 
   608     entities = query.fetch(self.BATCH_SIZE + 1)
   611     entities = query.fetch(batch_size + 1)
   609 
   612 
   610     next_key = None
   613     next_key = None
   611     if len(entities) == self.BATCH_SIZE + 1:
   614     if len(entities) == batch_size + 1:
   612       next_entity = entities.pop()
   615       next_entity = entities.pop()
   613       next_key = next_entity.key()
   616       next_key = next_entity.key()
   614 
   617 
   615     return entities, next_key
   618     return entities, next_key
   616 
   619