equal
deleted
inserted
replaced
506 result.extend(data) |
506 result.extend(data) |
507 offset = offset + chunk |
507 offset = offset + chunk |
508 |
508 |
509 return result |
509 return result |
510 |
510 |
|
511 def entityIterator(self, queryGen, batchSize = 100): |
|
512 """Iterator that yields an entity in batches. |
|
513 |
|
514 Args: |
|
515 queryGen: should return a Query object |
|
516 batchSize: how many entities to retrieve in one datastore call |
|
517 |
|
518 Retrieved from http://tinyurl.com/d887ll (AppEngine cookbook). |
|
519 """ |
|
520 |
|
521 # AppEngine will not fetch more than 1000 results |
|
522 batchSize = min(batchSize,1000) |
|
523 |
|
524 done = False |
|
525 count = 0 |
|
526 key = None |
|
527 |
|
528 while not done: |
|
529 query = queryGen() |
|
530 if key: |
|
531 query.filter("__key__ > ",key) |
|
532 results = query.fetch(batchSize) |
|
533 for result in results: |
|
534 count += 1 |
|
535 yield result |
|
536 if batchSize > len(results): |
|
537 done = True |
|
538 else: |
|
539 key = results[-1].key() |
|
540 |
511 def _createField(self, entity_properties, name): |
541 def _createField(self, entity_properties, name): |
512 """Hook called when a field is created. |
542 """Hook called when a field is created. |
513 |
543 |
514 To be exact, this method is called for each field (that has a value |
544 To be exact, this method is called for each field (that has a value |
515 specified) on an entity that is being created. |
545 specified) on an entity that is being created. |