Skip to content

Refactor the producers list replace the reference with the id as map key#249

Merged
Gsantomaggio merged 14 commits intomasterfrom
fix/producers_list
Oct 2, 2025
Merged

Refactor the producers list replace the reference with the id as map key#249
Gsantomaggio merged 14 commits intomasterfrom
fix/producers_list

Conversation

@Gsantomaggio
Copy link
Copy Markdown
Member

@Gsantomaggio Gsantomaggio commented Sep 26, 2025

Refactors the producer implementation to use publisher IDs as map keys instead of reference strings, improving performance and consistency in publisher management.

  • Replaces string references with integer IDs as the primary key for tracking publishers
  • Updates handler registration to use publisher IDs instead of references
  • Modifies publisher creation logic to handle optional references

Breaking changes

  • It is not possible to subscribe the same stream twice to the same consumer instance anymore

Signed-off-by: Gabriele Santomaggio <[email protected]>
@Gsantomaggio Gsantomaggio changed the title wip Refactor the producers list replace the reference with the id as map key Sep 26, 2025
This reverts commit 53ca444.
Signed-off-by: Gabriele Santomaggio <[email protected]>
Signed-off-by: Gabriele Santomaggio <[email protected]>
Signed-off-by: Gabriele Santomaggio <[email protected]>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors the producer implementation to use publisher IDs as map keys instead of reference strings, improving performance and consistency in publisher management.

  • Replaces string references with integer IDs as the primary key for tracking publishers
  • Updates handler registration to use publisher IDs instead of references
  • Modifies publisher creation logic to handle optional references

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rstream/producer.py Core refactoring to use publisher IDs as keys and handle optional references
rstream/client.py Updates declare_publisher to accept optional reference parameter
rstream/consumer.py Re-enables max consumers validation and adjusts subscription ID handling
tests/test_producer.py Updates test calls to use named parameters and publisher names
tests/test_validate_id.py Adds new test to validate publisher ID assignment and cleanup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread rstream/producer.py Outdated
Comment thread rstream/producer.py Outdated
Comment thread rstream/producer.py Outdated
Comment thread tests/test_producer.py Outdated
Gsantomaggio and others added 6 commits September 29, 2025 16:22
Signed-off-by: Gabriele Santomaggio <[email protected]>
Signed-off-by: Gabriele Santomaggio <[email protected]>
@Gsantomaggio Gsantomaggio marked this pull request as ready for review September 30, 2025 13:57
@Gsantomaggio Gsantomaggio marked this pull request as draft September 30, 2025 13:57
- it is possible to have only one stream for Consumer class
- add cluster tests
- use the publisher id to handle the publishers list
- replace list of used ids with an atomic integer

Signed-off-by: Gabriele Santomaggio <[email protected]>
@Gsantomaggio Gsantomaggio self-assigned this Oct 1, 2025
@Gsantomaggio Gsantomaggio added this to the 0.4.0 milestone Oct 1, 2025
@Gsantomaggio Gsantomaggio requested a review from Copilot October 1, 2025 13:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread rstream/producer.py Outdated
Comment thread rstream/producer.py
Comment on lines +784 to +785
stream = self._publishers[publisher_id].stream
if publisher_id in self._publishers:
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential KeyError if publisher_id is not in self._publishers. The stream assignment on line 784 should be moved inside the conditional check on line 785.

Copilot uses AI. Check for mistakes.
Comment thread rstream/consumer.py
await self._clients[stream].remove_stream(stream)
await self._clients[stream].free_available_id(subscriber.subscription_id)
await self._clients[stream].free_available_id()
del self._clients[stream]
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client is being deleted immediately after freeing the available ID, which may not be correct if other subscribers are using the same client. Consider checking if the client is still needed before deletion.

Suggested change
del self._clients[stream]
# Only delete the client if no other subscribers are using this stream
if not any(
s.stream == stream and sid != subscriber_id
for sid, s in self._subscribers.items()
):
del self._clients[stream]

Copilot uses AI. Check for mistakes.
Gsantomaggio and others added 2 commits October 1, 2025 15:59
Signed-off-by: Gabriele Santomaggio <[email protected]>
@Gsantomaggio Gsantomaggio added enhancement New feature or request breaking change Introduce a breaking change labels Oct 2, 2025
@Gsantomaggio Gsantomaggio marked this pull request as ready for review October 2, 2025 09:40
@Gsantomaggio Gsantomaggio merged commit 5f6b581 into master Oct 2, 2025
1 check passed
@Gsantomaggio Gsantomaggio deleted the fix/producers_list branch October 2, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduce a breaking change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants