Reuse a persistent aiohttp.ClientSession in GiphyService #26

Closed
opened 2026-02-20 06:49:40 +00:00 by cal · 1 comment
Owner

Description

services/giphy_service.py:189 and :248 — Both GIF methods create a new aiohttp.ClientSession per invocation. Creating and tearing down a session on every call has measurable overhead (DNS resolution, TCP handshake). The service already has __init__-based state; a session could be stored and reused.

File Locations

  • services/giphy_service.py:189
  • services/giphy_service.py:248

Labels

performance, tech-debt

Priority

low

## Description `services/giphy_service.py:189` and `:248` — Both GIF methods create a new `aiohttp.ClientSession` per invocation. Creating and tearing down a session on every call has measurable overhead (DNS resolution, TCP handshake). The service already has `__init__`-based state; a session could be stored and reused. ## File Locations - `services/giphy_service.py:189` - `services/giphy_service.py:248` ## Labels performance, tech-debt ## Priority low
cal added the
ai-working
label 2026-03-05 07:31:07 +00:00
cal added the
status/in-progress
label 2026-03-05 07:32:07 +00:00
cal added
status/pr-open
and removed
status/in-progress
labels 2026-03-05 07:33:14 +00:00
Author
Owner

Opened PR #66 to fix this.

Added self._session to GiphyService.__init__ and a _get_session() lazy initialiser that creates (or recreates if closed) a single aiohttp.ClientSession. Both get_disappointment_gif and get_gif now call self._get_session() instead of creating a new session per invocation.

Opened PR #66 to fix this. Added `self._session` to `GiphyService.__init__` and a `_get_session()` lazy initialiser that creates (or recreates if closed) a single `aiohttp.ClientSession`. Both `get_disappointment_gif` and `get_gif` now call `self._get_session()` instead of creating a new session per invocation.
cal added
ai-pr-opened
and removed
ai-working
labels 2026-03-05 07:33:26 +00:00
cal closed this issue 2026-03-07 03:31:04 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-v2#26
No description provided.