Skip to content

Commit 5891055

Browse files
committed
[Chore] Use Set instead of hash for storing subscribed topics
1 parent 47f3794 commit 5891055

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/kafka/consumer.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def initialize(cluster:, logger:, instrumenter:, group:, fetcher:, offset_manage
7676

7777
# Hash storing topics that are already being subscribed
7878
# When subcribing to a new topic, if it's already being subscribed before, skip it
79-
@subscribed_topics = {}
79+
@subscribed_topics = Set.new
8080
end
8181

8282
# Subscribes the consumer to a topic.
@@ -595,8 +595,8 @@ def subscribe_to_regex(topic_regex, default_offset, start_from_beginning, max_by
595595
end
596596

597597
def subscribe_to_topic(topic, default_offset, start_from_beginning, max_bytes_per_partition)
598-
return if @subscribed_topics[topic]
599-
@subscribed_topics[topic] = true
598+
return if @subscribed_topics.include?(topic)
599+
@subscribed_topics.add(topic)
600600

601601
@group.subscribe(topic)
602602
@offset_manager.set_default_offset(topic, default_offset)

0 commit comments

Comments
 (0)