Commit Graph

449 Commits

Author SHA1 Message Date
Georges-Antoine Assi
e4816911d9 Better performance for large collections 2024-08-28 11:44:31 -04:00
Georges-Antoine Assi
f00749e20c add back ms.ico + add sms to moby list 2024-08-27 10:13:58 -04:00
Michael Manganiello
a85c84a7d4 misc: Use single SQLAlchemy engine and session maker
As recommended by SQLAlchemy [1], this change makes a single
instantiation of the database engine and session maker, instead of one
entity per handler.

It also uses the provided `URL` constructor to better define the
database URL structure.

[1] https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage
2024-08-21 09:56:28 -03:00
Michael Manganiello
0fad8ac282 feat: Use nginx mod_zip to generate multi-file zip downloads
This change installs and configures the `mod_zip` nginx module [1],
which allows nginx to stream ZIP files directly.

It includes a workaround needed to correctly calculate CRC-32 values for
included files, by including a new `server` section listening at port
8081, only used for the file requests to be upstream subrequests that
correctly trigger the CRC-32 calculation logic.

Also, to be able to provide a `m3u` file generated on the fly, we add a
`/decode` endpoint fully implemented in nginx using NJS, which receives
a `value` URL param, and decodes it using base64. The decoded value is
returned as the response.

That way, the contents of the `m3u` file is base64-encoded, and set as
part of the response, for `mod_zip` to include it in the ZIP file.

[1] https://github.com/evanmiller/mod_zip
2024-08-20 22:39:33 -03:00
Georges-Antoine Assi
49e493802f Skip compressed files if theyre invalid 2024-08-18 14:14:38 -04:00
Michael Manganiello
0fdbbe4625 misc: Upgrade Python to v3.12 and Alpine to v3.20
Included upgrades:
* Python: v3.12
* Alpine: v3.20 (which uses Python 3.12)
* nginx: v1.27.1
2024-08-15 20:14:32 -03:00
Georges-Antoine Assi
b3a50021b7 run quick before hash scan 2024-08-12 11:57:47 -04:00
Georges-Antoine Assi
bc08e05a19 changes from self review 2024-08-11 23:09:58 -04:00
Georges-Antoine Assi
75b856bf94 only calc hashes in certian conditions 2024-08-11 22:54:35 -04:00
Georges-Antoine Assi
1ea1b326d3 move hashes to rom model 2024-08-11 22:38:22 -04:00
Georges-Antoine Assi
c3b754a2aa fix file meta order 2024-08-11 20:05:04 -04:00
Georges-Antoine Assi
56037070fb only calc hashes exlpicit 2024-08-11 19:36:52 -04:00
Georges-Antoine Assi
a4e162e2c1 Merge branch 'master' into calc-file-hashes-roms 2024-08-11 19:07:06 -04:00
Georges-Antoine Assi
7e086cec67 fixes from code review 2024-08-11 19:06:16 -04:00
Georges-Antoine Assi
195b86b573 even more cleanup 2024-08-09 11:46:07 -04:00
Georges-Antoine Assi
90e0e688b7 Merge branch 'master' into calc-file-hashes-roms 2024-08-09 11:36:50 -04:00
Georges-Antoine Assi
5f0577b900 more cleanup 2024-08-09 00:17:11 -04:00
Georges-Antoine Assi
1ae9cd0b5a remove unneded code 2024-08-09 00:10:31 -04:00
Georges-Antoine Assi
3a1986f453 single lines for the virtual table 2024-08-08 23:27:31 -04:00
Georges-Antoine Assi
cd54d902a7 create database view for sibling roms 2024-08-08 22:25:50 -04:00
Michael Manganiello
8abbae4c02 misc: Make backend handle URLs with trailing slash
According to multiple FastAPI discussions [1], FastAPI only includes a
built-in mechanism to redirect requests including a trailing slash, to
its variation without slash, using a `307` status code.

This can be an issue when certain clients do not send the same headers
on the redirected request.

This change adds a custom FastAPI `APIRouter`, that registers both route
path variations (with and without trailing slash), while only marking
the path without slash for being included in the OpenAPI schema.

[1] https://github.com/fastapi/fastapi/discussions/7298
2024-08-07 00:22:21 -03:00
Georges-Antoine Assi
0139e3a13a fix tests 2024-07-27 16:56:13 -04:00
Georges-Antoine Assi
2c2adb4112 Merge branch 'master' into calc-file-hashes-roms 2024-07-27 16:39:46 -04:00
Georges-Antoine Assi
f01f5ce5b5 trunk fixes 2024-07-27 16:38:57 -04:00
Georges-Antoine Assi
9386ca9e4a changes from self-review 2024-07-27 16:31:32 -04:00
Georges-Antoine Assi
3a9cef24e0 get it all wokring 2024-07-27 13:30:52 -04:00
Georges-Antoine Assi
ecc021e824 Merge branch 'master' into calc-file-hashes-roms 2024-07-27 12:17:18 -04:00
Michael Manganiello
749e4d65c1 misc: Use PYTEST_VERSION variable to detect Pytest runs
Pytest v8.2 introduced the `PYTEST_VERSION` environment variable [1],
that can be used to check if code is running from within a pytest run.

This way, we can avoid checking the loaded `sys` modules.

[1] https://docs.pytest.org/en/stable/changelog.html#id57
2024-07-27 12:03:44 -03:00
Michael Manganiello
9319081ff6 fix: Return early if IGDB finds an exact match
This improvement avoids extra IGDB API requests when a received Rom is
an exact match. It avoids up to 2 requests per Rom, when an exact match
is found.
2024-07-27 00:53:27 -03:00
Michael Manganiello
96699a2f1b fix: Catch ProtocolError when writing screenshots/covers 2024-07-26 21:19:18 -03:00
Michael Manganiello
aced1f1ff2 misc: Migrate IGDBBaseHandler to async
Convert `IGDBBaseHandler` methods to be asynchronous, and use an `httpx`
async client, instead of `requests` sync client.

This change also removes the direct dependency with `requests`, as the
project no longer uses it, preferring `httpx` instead.
2024-07-26 21:19:01 -03:00
Georges-Antoine Assi
efc0b75cdb Merge branch 'master' into calc-file-hashes-roms 2024-07-25 22:42:46 -04:00
Georges-Antoine Assi
141edf9d2e Merge pull request #1028 from rommapp/share-public-collections
Public collections
2024-07-25 22:38:21 -04:00
Georges-Antoine Assi
ad3a588631 filter collections for each user 2024-07-25 19:53:44 -04:00
Zurdi
38a500f577 Merge branch 'master' into romm-1025 2024-07-25 21:35:18 +02:00
Georges-Antoine Assi
7555c0607a [ROMM-1025] Replace game-and-watch with g-and-w 2024-07-25 14:26:06 -04:00
Georges-Antoine Assi
92b23656aa start making collecitons public 2024-07-25 13:49:43 -04:00
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
db1787dff4 fix trunk issues 2024-07-18 22:03:08 -04:00
Georges-Antoine Assi
77afe55625 add support for extracting content in compressed files 2024-07-18 21:50:24 -04:00
Georges-Antoine Assi
591e41a4d5 start checking for specific file exts 2024-07-18 20:51:48 -04:00
Georges-Antoine Assi
2e91c440e3 Read into mem in chunks 2024-07-16 17:42:25 -04:00
Georges-Antoine Assi
2b2ff875ee Calculate hashes for rom files 2024-07-15 18:27:29 -04: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