Skip to content

Commit

Permalink
EventNotifier: Add TODO for avoiding duplicate updates
Browse files Browse the repository at this point in the history
  • Loading branch information
roekatz committed Mar 26, 2024
1 parent c3376a8 commit 71127da
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fastapi_websocket_pubsub/event_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ async def notify(
# TODO improve with reader/writer lock pattern - so multiple notifications can happen at once
async with self._get_subscribers_lock():
for topic in topics:
# TODO: Multiple topics can have the same subscriber - we should first aggregate the entire list of subscribers for all topics,
# and only then create the `callbacks` list so each subscriber is called only once (to avoid duplicated updates)
subscribers = self._topics.get(topic, {})

# handle direct topic subscribers (work on copy to avoid changes after we got the callbacks running)
callbacks.append(
self.callback_subscribers(
Expand Down

0 comments on commit 71127da

Please sign in to comment.