Skip to content

Commit 983267a

Browse files
committed
make event pools use a set for connections
1 parent 0d1a339 commit 983267a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sogs/events.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from flask import g
1717

1818
# pools for event propagation
19-
_pools = defaultdict(list)
19+
_pools = defaultdict(set)
2020

2121
status_OK = 'OK'
2222
status_ERR = 'ERROR'
@@ -111,7 +111,7 @@ def handle_subscribe(*events, conn=None):
111111

112112
global _pools
113113
for name in sub:
114-
_pools[name].append(conn)
114+
_pools[name].add(conn)
115115
app.logger.debug(f"sub {conn} to {len(sub)} events")
116116

117117

@@ -127,7 +127,8 @@ def handle_unsubscribe(*events, conn=None):
127127

128128
global _pools
129129
for name in unsub:
130-
_pools[name].remove(conn)
130+
if conn in _pools[name]:
131+
_pools[name].remove(conn)
131132
app.logger.debug(f"unsub {conn} to {len(unsub)} events")
132133

133134

0 commit comments

Comments
 (0)