Add chunking to the websocket topics management
This commit is contained in:
1 parent
5f54c26f4a
commit
5d7a697c2b
1 file changed
+19
-16
+19
-16
@@ -14,6 +14,7 @@ from exceptions import MinerException, WebsocketClosed
|
|||||||
from constants import PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT
|
from constants import PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT
|
||||||
from utils import (
|
from utils import (
|
||||||
CHARS_ASCII,
|
CHARS_ASCII,
|
||||||
|
chunk,
|
||||||
task_wrapper,
|
task_wrapper,
|
||||||
create_nonce,
|
create_nonce,
|
||||||
json_minify,
|
json_minify,
|
||||||
@@ -210,30 +211,32 @@ class Websocket:
|
|||||||
if removed:
|
if removed:
|
||||||
topics_list = list(map(str, removed))
|
topics_list = list(map(str, removed))
|
||||||
ws_logger.debug(f"Websocket[{self._idx}]: Removing topics: {', '.join(topics_list)}")
|
ws_logger.debug(f"Websocket[{self._idx}]: Removing topics: {', '.join(topics_list)}")
|
||||||
await self.send(
|
for topics in chunk(topics_list, 20):
|
||||||
{
|
await self.send(
|
||||||
"type": "UNLISTEN",
|
{
|
||||||
"data": {
|
"type": "UNLISTEN",
|
||||||
"topics": topics_list,
|
"data": {
|
||||||
"auth_token": auth_state.access_token,
|
"topics": topics,
|
||||||
|
"auth_token": auth_state.access_token,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
self._submitted.difference_update(removed)
|
self._submitted.difference_update(removed)
|
||||||
# handle added topics
|
# handle added topics
|
||||||
added = current.difference(self._submitted)
|
added = current.difference(self._submitted)
|
||||||
if added:
|
if added:
|
||||||
topics_list = list(map(str, added))
|
topics_list = list(map(str, added))
|
||||||
ws_logger.debug(f"Websocket[{self._idx}]: Adding topics: {', '.join(topics_list)}")
|
ws_logger.debug(f"Websocket[{self._idx}]: Adding topics: {', '.join(topics_list)}")
|
||||||
await self.send(
|
for topics in chunk(topics_list, 20):
|
||||||
{
|
await self.send(
|
||||||
"type": "LISTEN",
|
{
|
||||||
"data": {
|
"type": "LISTEN",
|
||||||
"topics": topics_list,
|
"data": {
|
||||||
"auth_token": auth_state.access_token,
|
"topics": topics,
|
||||||
|
"auth_token": auth_state.access_token,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
self._submitted.update(added)
|
self._submitted.update(added)
|
||||||
|
|
||||||
async def _gather_recv(self, messages: list[JsonType], timeout: float = 0.5):
|
async def _gather_recv(self, messages: list[JsonType], timeout: float = 0.5):
|
||||||
|
|||||||
Reference in new issue
Block a user