diff --git a/CHANGELOG.md b/CHANGELOG.md index 93be993..65c72b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index ad2dc08..a6daa29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/snek/view/rpc/__init__.py b/src/snek/view/rpc/__init__.py index 99120fb..6dd644d 100644 --- a/src/snek/view/rpc/__init__.py +++ b/src/snek/view/rpc/__init__.py @@ -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,18 +168,21 @@ class RPCView(BaseView): user_uid = session.get("uid") if user_uid and self.services: await self.services.socket.add(ws, user_uid) - try: - async for subscription in self.services.channel_member.find( - user_uid=user_uid, - deleted_at=None, - is_banned=False, - ): - if subscription: - channel_uid = safe_get(subscription, "channel_uid") - if channel_uid: - 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)}") + # 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, + deleted_at=None, + is_banned=False, + ): + if subscription: + channel_uid = safe_get(subscription, "channel_uid") + if channel_uid: + 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)}")