Commit Graph

407 Commits

Author SHA1 Message Date
Michael Manganiello
2bfc3c4c7e misc: Refactor scan process by splitting single function
This change mainly refactors the `scan_platforms` function, moving part
of its logic to `_identify_platform`, `_identify_firmware`, and
`_identify_rom`.

The logic is simpler this way, each smaller function returns `ScanStats`
that can be merged by the caller, and it simplifies future performance
improvements.
2024-07-25 10:29:46 -03:00
Michael Manganiello
959e896aa3 misc: Replace pytest-vcr dependency with pytest-recording
`pytest-vcr` [1] is no longer maintained (last commit was in 2020), and
`VCR.py` recommends [2] `pytest-recording` instead.

Also, `pytest-vcr` does not correctly support `httpx` [3].

This change also removes unused cassettes.

[1] https://github.com/ktosiek/pytest-vcr
[2] https://vcrpy.readthedocs.io/en/latest/usage.html#pytest-integration
[3] https://github.com/ktosiek/pytest-vcr/issues/46
2024-07-24 12:39:41 -03:00
Michael Manganiello
56066d6765 misc: Migrate filesystem resource handler to async
For filesystem resource handler, `requests` calls have been replaced
with `httpx`, and file I/O has been replaced with `anyio` utils.

The existing approach to save covers and screenshots, by calling
`shutil.copyfileobj` with the raw response is no longer needed. `httpx`
does not provide a file-like object when streaming [1], so there's no
easy drop-in replacement.

However, the applied solution correctly builds the file iteratively, by
consuming the response in chunks.

[1] https://github.com/encode/httpx/discussions/2296
2024-07-24 00:18:17 -03:00
Michael Manganiello
7c6dfa8e50 feat: Use ContextVar to share httpx AsyncClient instance between requests 2024-07-23 01:29:32 -03:00
Michael Manganiello
6d8a8714f5 misc: Migrate MobyGamesHandler to async
Convert `MobyGamesHandler` methods to be asynchronous, and use an
`httpx` async client, instead of `requests` sync client.
2024-07-22 01:09:36 -03:00
Michael Manganiello
6eb8e6aeff misc: Add Redis async cache
Introduce an asynchronous Redis instance to be used in async functions.
Also, this change migrates most of the sync cache usage to the new async
cache.
2024-07-21 18:23:19 -03:00
Georges-Antoine Assi
d05a539871 Fix covers deleted when uploading extension other then PNG 2024-07-14 17:30:05 -04:00
Michael Manganiello
f20a9ffe34 fix: Avoid recursive os.walk calls
`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.
2024-07-13 15:30:04 -03:00
zurdi
884e7a35ac fixed re-download lost covers 2024-07-11 08:47:59 +02:00
Michael Manganiello
b61bb11bce feat: Use async requests to retrieve SteamGridDB covers
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.
2024-07-09 22:37:14 -03:00
zurdi
f7b14b43d6 fixed everything from trunk 2024-07-09 13:43:14 +02:00
Michael Manganiello
23ef1fb419 fix: Correctly traverse SteamGridDB API pages
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.
2024-07-07 12:16:30 -03:00
Zurdi
b1f5ae50e5 fixes from PR review 2024-07-06 17:25:08 +02:00
Zurdi
65589393c8 Merge remote-tracking branch 'origin/master' into feature/setup-wizard 2024-07-05 21:13:12 +02:00
Zurdi
ebaa5d6520 fixed filter roms both by platform and collection 2024-07-05 20:59:14 +02:00
zurdi
8a2a4d6099 fixes from trunk 2024-07-04 23:54:18 +02:00
zurdi
3d27a05c22 fixes from trunk 2024-07-04 23:47:14 +02:00
Zurdi
7cdc12c7b2 fixed stats and user handler 2024-07-04 23:11:07 +02:00
zurdi
4b81c01140 fixed tests 2024-07-04 22:26:35 +02:00
zurdi
2ec4debd61 setup wizard added 2024-07-04 14:19:00 +02:00
zurdi
f2f202de9e add user collections to details 2024-07-04 01:25:44 +02:00
Zurdi
5126c56ba9 get collections for detailed rom info 2024-07-04 00:05:37 +02:00
Zurdi
2a7def81ac added reactivity to collections 2024-07-03 21:58:58 +02:00
zurdi
59c2a51a6f added collection cover management 2024-07-03 14:31:17 +02:00
Zurdi
23e0a064ab added update collection endpoint 2024-07-02 23:34:50 +02:00
zurdi
1d6ba70080 collections get_roms endpoint added 2024-07-02 14:31:27 +02:00
Zurdi
cc9e05f668 collections migration added 2024-07-01 23:47:15 +02:00
Georges-Antoine Assi
7530fdd576 mega refactor of pr 2024-07-01 15:12:07 -04:00
Zurdi
a937b0ddcf added publicNotes schema 2024-07-01 17:42:23 +02:00
zurdi
15f7522da5 rom db hanlder refactor to adapt to user_rom_props 2024-07-01 15:30:14 +02:00
zurdi
66e185db47 Merge branch 'master' into feature/fav_for_siblings 2024-07-01 08:34:04 +02:00
Georges-Antoine Assi
b7c2350123 Merge branch 'master' into misc/simplify-stat-query-platforms 2024-06-30 20:24:47 -04:00
Georges-Antoine Assi
bffffcc9c3 Merge pull request #969 from adamantike/fix/implement-total-filesize-stat
fix: Add implementation for total filesize statistic
2024-06-30 20:00:00 -04:00
Michael Manganiello
bc13e69a5b misc: Simplify statistics query to retrieve platforms count
Instead of counting `Platform` rows, and filtering based on a subquery
in `Rom`, we can simply count the different `platform_id` values in
`Rom`.
2024-06-30 17:55:11 -03:00
Michael Manganiello
b0f834282a fix: Add implementation for total filesize statistic
Add query that calculates total filesize statistic, currently hardcoded
to zero.
2024-06-30 17:40:48 -03:00
Michael Manganiello
8281d5679b misc: Split database handler logic to get/list entities
The current implementation for some of the database handlers, where the
same method is used to retrieve either a single entity (when an `id` is
passed), a list of entities, or `None`, makes the typing and overall
design more complex.

This change simplifies database handlers, by having two separate methods
where appropiate:

* A method that receives an `id`, and returns either an entity, or `None`.
* A method that optionally receives filters, and returns (depending on
  the current handler implementation) a list of entities, or a `Select`
  object that allows chaining more SQLAlchemy operations.
2024-06-30 13:12:48 -03:00
zurdi
aff4bb65de add user_rom_props to get_roms 2024-06-30 13:26:50 +02:00
zurdi
4749bf84c6 atomic update user_rom_props 2024-06-30 01:50:08 +02:00
Zurdi
d3381e16b0 Update backend/handler/auth/base_handler.py
Co-authored-by: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com>
2024-06-29 18:20:01 +02:00
Zurdi
43cd6a8383 added main sibling per user 2024-06-29 14:09:41 +02:00
zurdi
0a0bab6730 migrated rom_notes to user_rom_props 2024-06-29 11:26:16 +02:00
Zurdi
c022e9cef7 added user_rom_props entity 2024-06-29 00:13:28 +02:00
Zurdi
7d9ce05c3c added main sibling to the front and database 2024-06-27 21:50:04 +02:00
zurdi
a07133d678 added filter for static/animated cover 2024-06-27 16:45:56 +02:00
zurdi
7dfbcc9a0b dinamic ratio for small artwork 2024-06-26 19:37:50 +02:00
Zurdi
c8f9015561 Merge branch 'master' into feature/steamgriddb 2024-06-26 18:17:03 +02:00
zurdi
180c373e1e steamgridDB integration added 2024-06-26 17:36:02 +02:00
Michael Manganiello
3bd37165d4 fix: Call Redis HSET in bulk 2024-06-26 00:17:49 -03:00
Georges-Antoine Assi
176c57c792 run trunk fmt 2024-06-23 18:17:19 -03:00
Michael Manganiello
33ac3ca56d misc: Apply changes generated by pyupgrade
Changes automatically made by
[`pyupgrade`](https://github.com/asottile/pyupgrade), using the
`--py311-plus` flag, to be compatible with Python 3.11.
2024-06-23 18:17:08 -03:00