Skip to content

Commit

Permalink
feat: BulkWriter implementation (#384)
Browse files Browse the repository at this point in the history
* feat: added `write` method to batch classes

* added docstrings to all 3 batch classes

instead of just the base

* updated batch classes to remove control flag

now branches logic via subclasses

* fixed broken tests off abstract class

* fixed docstring

* refactored BulkWriteBatch

this commit increases the distance between WriteBatch and BulkWriteBatch

* began adding [Async]BulkWriter

* continued implementation

* working impl or BW

* tidied up BW impl

* beginning of unit tests for BW

* fixed merge problem

* initial set of BW unit tests

* refactored bulkwriter sending mechanism

now consumes off the queue and schedules on the main thread, only going async to actually send

* final CI touch ups

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md

* moved BulkWriter parameters to options format

* rebased off master

* test fixes

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
craiglabenz and gcf-owl-bot[bot] committed Aug 10, 2021
1 parent 783d9e3 commit 70e255d
Show file tree
Hide file tree
Showing 10 changed files with 968 additions and 9 deletions.
17 changes: 16 additions & 1 deletion google/cloud/firestore_v1/async_client.py
Expand Up @@ -43,13 +43,18 @@
DocumentSnapshot,
)
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
from google.cloud.firestore_v1.bulk_writer import (
BulkWriter,
BulkWriterOptions,
SendMode,
)
from google.cloud.firestore_v1.services.firestore import (
async_client as firestore_client,
)
from google.cloud.firestore_v1.services.firestore.transports import (
grpc_asyncio as firestore_grpc_transport,
)
from typing import Any, AsyncGenerator, Iterable, List
from typing import Any, AsyncGenerator, Iterable, List, Optional


class AsyncClient(BaseClient):
Expand Down Expand Up @@ -287,6 +292,16 @@ async def collections(
async for collection_id in iterator:
yield self.collection(collection_id)

def bulk_writer(self, send_mode: Optional[SendMode] = None) -> BulkWriter:
"""Get a BulkWriter instance from this client.
Returns:
:class:`@google.cloud.firestore_v1.bulk_writer.BulkWriter`:
A utility to efficiently create and save many `AsyncWriteBatch` instances
to the server.
"""
return BulkWriter(client=self, options=BulkWriterOptions(mode=send_mode))

def batch(self) -> AsyncWriteBatch:
"""Get a batch instance from this client.
Expand Down

0 comments on commit 70e255d

Please sign in to comment.