Skip to content

Commit

Permalink
Reduce cookies file size by removing empty cookie entries
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Sep 14, 2024
1 parent 1684f92 commit 77e2ce0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ async def shutdown(self) -> None:
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
Expand Down

0 comments on commit 77e2ce0

Please sign in to comment.