perf: increase websocket heartbeat interval and load subscriptions asynchronously
This commit is contained in:
parent
8b1ce1da67
commit
403389e3fd
@ -35,6 +35,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Version 1.36.0 - 2026-02-14
|
||||
|
||||
Increases the websocket heartbeat interval to reduce network overhead and improve connection efficiency. Loads subscriptions asynchronously to enhance responsiveness during data retrieval.
|
||||
|
||||
**Changes:** 1 files, 29 lines
|
||||
**Languages:** Python (29 lines)
|
||||
|
||||
## Version 1.35.0 - 2026-01-31
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "Snek"
|
||||
version = "1.35.0"
|
||||
version = "1.36.0"
|
||||
readme = "README.md"
|
||||
#license = { file = "LICENSE", content-type="text/markdown" }
|
||||
description = "Snek Chat Application by Molodetz"
|
||||
|
||||
@ -155,7 +155,7 @@ class RPCView(BaseView):
|
||||
logger.debug(f"Schedule failed: {safe_str(ex)}")
|
||||
|
||||
try:
|
||||
ws = web.WebSocketResponse(heartbeat=30.0, autoping=True)
|
||||
ws = web.WebSocketResponse(heartbeat=300.0, autoping=True)
|
||||
await ws.prepare(self.request)
|
||||
except Exception as ex:
|
||||
logger.warning(f"Failed to prepare WebSocket: {safe_str(ex)}")
|
||||
@ -168,6 +168,8 @@ class RPCView(BaseView):
|
||||
user_uid = session.get("uid")
|
||||
if user_uid and self.services:
|
||||
await self.services.socket.add(ws, user_uid)
|
||||
# Load subscriptions in background to avoid blocking WebSocket handshake
|
||||
async def load_subscriptions():
|
||||
try:
|
||||
async for subscription in self.services.channel_member.find(
|
||||
user_uid=user_uid,
|
||||
@ -180,6 +182,7 @@ class RPCView(BaseView):
|
||||
await self.services.socket.subscribe(ws, channel_uid, user_uid)
|
||||
except Exception as ex:
|
||||
logger.warning(f"Failed to subscribe to channels: {safe_str(ex)}")
|
||||
asyncio.create_task(load_subscriptions())
|
||||
except Exception as ex:
|
||||
logger.warning(f"Session initialization failed: {safe_str(ex)}")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user