From 08de3b1a405bda2c0de9174d7f82a619dd96b775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Thu, 19 Sep 2019 11:53:46 +0200 Subject: _artifactcache.py: Create ArtifactServiceStub in _configure_protocols() There is no need to create a new stub for every request. This also matches what SourceRemote does. --- src/buildstream/_artifactcache.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py index 0e2eb1091..2f2fdc8cb 100644 --- a/src/buildstream/_artifactcache.py +++ b/src/buildstream/_artifactcache.py @@ -37,6 +37,11 @@ from . import utils # artifact remotes. # class ArtifactRemote(BaseRemote): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.artifact_service = None + # _configure_protocols(): # # Configure the protocols used by this remote as part of the @@ -44,7 +49,6 @@ class ArtifactRemote(BaseRemote): # Remote.init(), and is expected to fail when called by itself. # def _configure_protocols(self): - # Add artifact stub capabilities_service = buildstream_pb2_grpc.CapabilitiesStub(self.channel) # Check whether the server supports newer proto based artifact. @@ -67,6 +71,9 @@ class ArtifactRemote(BaseRemote): raise ArtifactError( "Configured remote does not support artifact service") + # Set up artifact stub + self.artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel) + # get_artifact(): # # Get an artifact proto for a given cache key from the remote. @@ -86,8 +93,7 @@ class ArtifactRemote(BaseRemote): artifact_request = artifact_pb2.GetArtifactRequest() artifact_request.cache_key = cache_key - artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel) - return artifact_service.GetArtifact(artifact_request) + return self.artifact_service.GetArtifact(artifact_request) # update_artifact(): # @@ -106,8 +112,7 @@ class ArtifactRemote(BaseRemote): update_request.cache_key = cache_key update_request.artifact.CopyFrom(artifact) - artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel) - artifact_service.UpdateArtifact(update_request) + self.artifact_service.UpdateArtifact(update_request) # An ArtifactCache manages artifacts. @@ -707,8 +712,7 @@ class ArtifactCache(BaseCache): request = artifact_pb2.GetArtifactRequest() request.cache_key = ref try: - artifact_service = artifact_pb2_grpc.ArtifactServiceStub(remote.channel) - artifact_service.GetArtifact(request) + remote.artifact_service.GetArtifact(request) except grpc.RpcError as e: if e.code() != grpc.StatusCode.NOT_FOUND: raise ArtifactError("Error when querying: {}".format(e.details())) -- cgit v1.2.1