Skip to content

Commit 0e257bb

Browse files
fix(pubsub): Remove get_topic lookup when publishing via lazy loading (#32273)
Co-authored-by: Yoshi Automation Bot <[email protected]>
1 parent 4cc40e4 commit 0e257bb

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

google-cloud-pubsub/lib/google/cloud/pubsub/publisher.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def reload!
213213
#
214214
def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, compression_bytes_threshold: nil,
215215
**extra_attrs, &block
216-
ensure_grpc!
216+
ensure_service!
217217
batch = BatchPublisher.new data,
218218
attributes,
219219
ordering_key,
@@ -337,7 +337,7 @@ def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, comp
337337
# publisher.async_publisher.stop!
338338
#
339339
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
340-
ensure_grpc!
340+
ensure_service!
341341
@async_publisher ||= AsyncPublisher.new name, service, **@async_opts
342342
@async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
343343
end
@@ -415,13 +415,6 @@ def self.from_name name, service, options = {}
415415
def ensure_service!
416416
raise "Must have active connection to service" unless service
417417
end
418-
419-
##
420-
# Ensures a Google::Cloud::PubSub::V1::Topic object exists.
421-
def ensure_grpc!
422-
ensure_service!
423-
reload! if reference?
424-
end
425418
end
426419
end
427420

google-cloud-pubsub/test/google/cloud/pubsub/publisher_test.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,14 @@
154154
mock.verify
155155
end
156156

157-
it "reloads the resource when publishing if created with skip_lookup: true" do
157+
it "does not reload the resource when publishing if created with skip_lookup: true" do
158158
mock = Minitest::Mock.new
159159
pubsub.service.mocked_topic_admin = mock
160160

161161
publisher = pubsub.publisher topic_name, skip_lookup: true
162162

163163
_(publisher).must_be :reference?
164164

165-
mock.expect :get_topic, Google::Cloud::PubSub::V1::Topic.new(topic_hash(topic_name)) do |actual_topic|
166-
actual_topic == {topic: topic_path(topic_name)}
167-
end
168-
169165
# Expect publish to be called
170166
message = "new-message-here"
171167
encoded_msg = message.encode(Encoding::ASCII_8BIT)
@@ -181,7 +177,7 @@
181177

182178
msg = publisher.publish message
183179

184-
_(publisher).wont_be :reference?
180+
_(publisher).must_be :reference?
185181
_(msg.message_id).must_equal "msg1"
186182

187183
mock.verify

0 commit comments

Comments
 (0)