Exemplo n.º 1
0
 def delete(self, table: str, partition: str, item_ids: Iterable[str]):
     num_deleted = 0
     for chunk in chunks(item_ids, self._BATCH_MAX_SIZE):
         batch = self._batch_factory()
         for item_id in chunk:
             batch.delete_entity(partition, item_id)
             num_deleted += 1
             self.log_debug('deleted %s/%s/%s', table, partition, item_id)
         self._client.commit_batch(table, batch)
     self.log_debug('deleted %d from %s/%s', num_deleted, table, partition)
Exemplo n.º 2
0
 def _iter_mailbox(self, email_address: str, page: int,
                   folder: str) -> Iterable[dict]:
     domain = get_domain(email_address)
     emails = self._mailbox_storage.iter(
         f'{domain}/{email_address}/{folder}')
     for i, resource_ids in enumerate(chunks(emails,
                                             AppConfig.EMAILS_PER_PAGE),
                                      start=1):
         if i != page:
             continue
         for resource_id in resource_ids:
             email_id = resource_id.split('/')[-1]
             email = self.get(email_id)
             if email:
                 yield email
Exemplo n.º 3
0
    def test_creates_nonfull_chunks(self):
        chunks = collections.chunks([1, 2, 3, 4], 3)

        self.assertEqual(list(chunks), [(1, 2, 3), (4, )])
Exemplo n.º 4
0
    def test_creates_fullsize_chunks(self):
        chunks = collections.chunks([1, 2, 3, 4], 2)

        self.assertEqual(list(chunks), [(1, 2), (3, 4)])