Copilot commented on code in PR #1459:
URL: https://github.com/apache/pulsar-client-go/pull/1459#discussion_r2745148206


##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions) 
(Consumer, error) {
                oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + RetryTopicSuffix
                oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + DlqTopicSuffix
 
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       retryTopic = oldRetryTopic
-               }
-
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       dlqTopic = oldDlqTopic
+               CheckTopicIsExists := func(topic string) bool {
+                       r, err := 
client.lookupService.GetPartitionedTopicMetadata(topic)
+                       return err == nil && r != nil && r.Partitions > 0
                }
 
+               //If the retryTopic or DLQTopic has already been set,
+               //there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetroTopic or oldDLQTopic

Review Comment:
   Comment should have a space after the comment marker. According to Go style 
guidelines, comments should be formatted as "// Comment text" rather than 
"//Comment text". Most other comments in this file follow this convention.
   ```suggestion
                // there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetroTopic or oldDLQTopic
   ```



##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions) 
(Consumer, error) {
                oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + RetryTopicSuffix
                oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + DlqTopicSuffix
 
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       retryTopic = oldRetryTopic
-               }
-
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       dlqTopic = oldDlqTopic
+               CheckTopicIsExists := func(topic string) bool {
+                       r, err := 
client.lookupService.GetPartitionedTopicMetadata(topic)
+                       return err == nil && r != nil && r.Partitions > 0
                }
 
+               //If the retryTopic or DLQTopic has already been set,
+               //there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetroTopic or oldDLQTopic

Review Comment:
   Typo in comment: "GetPartitiondTopicMetadata" should be 
"GetPartitionedTopicMetadata".
   ```suggestion
                //there is no need to perform GetPartitionedTopicMetadata 
operation on oldRetroTopic or oldDLQTopic
   ```



##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions) 
(Consumer, error) {
                oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + RetryTopicSuffix
                oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + DlqTopicSuffix
 
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       retryTopic = oldRetryTopic
-               }
-
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       dlqTopic = oldDlqTopic
+               CheckTopicIsExists := func(topic string) bool {
+                       r, err := 
client.lookupService.GetPartitionedTopicMetadata(topic)
+                       return err == nil && r != nil && r.Partitions > 0
                }
 
+               //If the retryTopic or DLQTopic has already been set,
+               //there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetroTopic or oldDLQTopic

Review Comment:
   The comment is misleading and doesn't accurately describe the logic below. 
When options.DLQ is nil (line 160), both topics are always checked regardless 
of whether they've been "set" or not. The actual optimization is in the else 
branch (lines 172-185), where GetPartitionedTopicMetadata is only called if the 
respective topic field is empty. Consider revising the comment to: "Check for 
old topic naming format. When DLQ policy is not provided, check both old topics 
for backward compatibility. When DLQ policy is provided, only check old topics 
for fields that are not already set."
   ```suggestion
                // Check for old topic naming format.
                // When DLQ policy is not provided, check both old topics for 
backward compatibility.
   ```



##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions) 
(Consumer, error) {
                oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + RetryTopicSuffix
                oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + DlqTopicSuffix
 
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       retryTopic = oldRetryTopic
-               }
-
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       dlqTopic = oldDlqTopic
+               CheckTopicIsExists := func(topic string) bool {

Review Comment:
   Function name should follow Go naming conventions: 'CheckTopicIsExists' 
should be 'checkTopicExists'. In Go, unexported (local) functions should start 
with a lowercase letter, and the name can be simplified to 'checkTopicExists' 
for better readability.



##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions) 
(Consumer, error) {
                oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + RetryTopicSuffix
                oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" + 
options.SubscriptionName + DlqTopicSuffix
 
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       retryTopic = oldRetryTopic
-               }
-
-               if r, err := 
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
-                       r != nil &&
-                       r.Partitions > 0 {
-                       dlqTopic = oldDlqTopic
+               CheckTopicIsExists := func(topic string) bool {
+                       r, err := 
client.lookupService.GetPartitionedTopicMetadata(topic)
+                       return err == nil && r != nil && r.Partitions > 0
                }
 
+               //If the retryTopic or DLQTopic has already been set,
+               //there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetroTopic or oldDLQTopic

Review Comment:
   Typo in comment: "oldRetroTopic" should be "oldRetryTopic".
   ```suggestion
                //there is no need to perform GetPartitiondTopicMetadata 
operation on oldRetryTopic or oldDLQTopic
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to