Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimize gapic calls #863

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ran blacken
  • Loading branch information
daniel-sanche committed Sep 7, 2023
commit 7a4a5ad8754b8b0bda759090ddbe007c0edc2269
74 changes: 38 additions & 36 deletions google/cloud/bigtable_v2/services/bigtable/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ def read_rows(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.read_rows]
rpc = self._client._transport._wrapped_methods[
self._client._transport.read_rows
]
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -376,13 +376,13 @@ def sample_row_keys(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.sample_row_keys]
rpc = self._client._transport._wrapped_methods[
self._client._transport.sample_row_keys
]
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -488,14 +488,14 @@ async def mutate_row(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.mutate_row]
rpc = self._client._transport._wrapped_methods[
self._client._transport.mutate_row
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -595,14 +595,14 @@ def mutate_rows(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.mutate_rows]
rpc = self._client._transport._wrapped_methods[
self._client._transport.mutate_rows
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -746,14 +746,14 @@ async def check_and_mutate_row(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.check_and_mutate_row]
rpc = self._client._transport._wrapped_methods[
self._client._transport.check_and_mutate_row
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -837,13 +837,13 @@ async def ping_and_warm(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.ping_and_warm]
rpc = self._client._transport._wrapped_methods[
self._client._transport.ping_and_warm
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata((("name", request.name),)),
)
metadata = tuple(metadata) + (_cached_to_metadata((("name", request.name),)),)

# Send the request.
response = await rpc(
Expand Down Expand Up @@ -955,14 +955,14 @@ async def read_modify_write_row(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[self._client._transport.read_modify_write_row]
rpc = self._client._transport._wrapped_methods[
self._client._transport.read_modify_write_row
]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -1044,7 +1044,9 @@ def generate_initial_change_stream_partitions(
"the individual field arguments should be set."
)

if not isinstance(request, bigtable.GenerateInitialChangeStreamPartitionsRequest):
if not isinstance(
request, bigtable.GenerateInitialChangeStreamPartitionsRequest
):
request = bigtable.GenerateInitialChangeStreamPartitionsRequest(request)

# If we have keyword arguments corresponding to fields on the
Expand All @@ -1065,9 +1067,7 @@ def generate_initial_change_stream_partitions(
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand Down Expand Up @@ -1164,9 +1164,7 @@ def read_change_stream(
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
_cached_to_metadata(
(("table_name", request.table_name),)
),
_cached_to_metadata((("table_name", request.table_name),)),
)

# Send the request.
Expand All @@ -1191,8 +1189,12 @@ async def __aexit__(self, exc_type, exc, tb):
gapic_version=package_version.__version__
)


@functools.lru_cache(32)
def _cached_to_metadata(params, qualified_enums=True):
return gapic_v1.routing_header.to_grpc_metadata(params, qualified_enums=qualified_enums)
return gapic_v1.routing_header.to_grpc_metadata(
params, qualified_enums=qualified_enums
)


__all__ = ("BigtableAsyncClient",)
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,6 @@ def _prep_wrapped_messages(self, client_info):
),
}



def close(self):
return self.grpc_channel.close()

Expand Down