2024-12-01
Aaron and I fixed an issue with WPD today, I made the PR and he gave it a sanity check.
Issue 22 - Concurrent requests caused the cache (aiohttp-client-cache
), which was using sqlite, to lock and fail.
This is a pretty big bottleneck, and was reported as early as June - Exception thrown when executing multiple parallel requests. As more and more users started using the main instance, database errors became a lot more frequent, second to ratelimits.
The solution? Switching to Redis. aiohttp-client-cache
can cache to Redis instead of /tmp
or an sqlite database. I setup an env file, with type validation - that took a bit of time. The cache setup itself was easy, a few lines and an if-else to decide between file or redis-based caching.
The associated pull request also adds some other stuff, namely:
- Eliot logging (I'm a fan of this now lol, just wish it didn't add a level of indentation)
- Type validation for API Responses
- Cache efficiency - images aren't cached anymore
- Cancel requests when the client disconnects
- Save requests where possible - this adds metadata retrieval to a part_id -> story_id request, it's comforting to have type validation when making embedded requests like this.
- The frontend allows IDs to be typed in again, which is something people missed
- Readability and standardization changes
late night programming again, I made a few silly mistakes that Aaron caught and fixed, love how seriously he takes testing lol - something to learn from him.