With the introduction of non-paginated responses for ROMs, JSON
responses for big collection could easily be at >1MiB.
This change adds a FastAPI-provided middleware to enable GZip
compression for responses greater than 1KiB.
`os.walk` is a generator that can iteratively navigate from the
specified path, top-bottom. However, most of the calls to `os.walk` in
the project cast the call to `list()`, which makes it traverse the path
and recursively find all nested directories.
This is commonly not needed, as we end up just using a `[0]` index to
only access the root path.
This change adds a few utils that simplifies listing files/directories,
and by default does it non-recursively. Performance gains shouldn't be
noticeable in systems with high-speed storage, but we can avoid the edge
cases of users having too many nested directories, by avoiding unneeded
I/O.
This change avoids blocking requests when retrieving covers from
SteamGridDB, which is the main bottleneck as the current implementation
iterates over paginated results for multiple games.
Using an asynchronous client like `httpx` provides a good performance
improvement, and reduces the latency when calling this endpoint.
Also, the inclusion of FastAPI `lifespan` allows instantiating a single
client on startup.
When testing with "Final Fantasy V Advance", the endpoint goes from ~9s
to ~1.5s to retrieve all covers.
The SteamGridDB API has a bug, where the `total` field for the paginated
endpoint `/v2/grids/game/:gameId` sometimes double/triple counts results
(e.g. returning `total=172` when there are actually 86 results).
To avoid this issue, this change relies on each page's number of
results. If the received page has less than the requested amount of
grids, we know that is the last page.
This change makes some database columns non-nullable, and includes the
migration to seamlessly upgrade the schema.
It includes:
* User and Platform names
* Every boolean column
Zip compression during multi-file ROM download is not needed. Commonly,
ROMs are already compressed, and trying to compress them again on the
fly does not reduce the generated file's size, while spending CPU power
and making the download slower because of the compression process being
the bottleneck.
By setting `level=0`, compression gets disabled, increasing download
speed, and reducing CPU usage. CPU still gets a usage peak, because of
Zip requiring a CRC32 calculation over each file's content.