From 77e2ce0c280da712970beeb66bae07e9f9a2a97b Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sun, 15 Sep 2024 00:25:31 +0200 Subject: [PATCH] Reduce cookies file size by removing empty cookie entries --- twitch.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/twitch.py b/twitch.py index 7557c34..5bba13f 100644 --- a/twitch.py +++ b/twitch.py @@ -489,6 +489,12 @@ class Twitch: await self.websocket.stop(clear_topics=True) if self._session is not None: cookie_jar = cast(aiohttp.CookieJar, self._session.cookie_jar) + # clear empty cookie entries off the cookies file before saving + # NOTE: Unfortunately, aiohttp provides no easy way of clearing empty cookies, + # so we need to access the private '_cookies' attribute for this. + for cookie_key, cookie in list(cookie_jar._cookies.items()): + if not cookie: + del cookie_jar._cookies[cookie_key] cookie_jar.save(COOKIES_PATH) await self._session.close() self._session = None