chore(sync): review-polish pass on the RetroArch manifest perf work

Rename cached_md5s to cached_hashes, since it also caches PSP member
hash maps, and keep its docstring to one line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-09-24 16:35:59 -04:00
parent 0c7633f4bb
commit bb9aa28ea6
3 changed files with 10 additions and 11 deletions

View File

@@ -587,7 +587,7 @@ async def build_psp_manifest_entries(
# The key is only stable while the row's content hash tracks the bytes.
cached = [(folder, save) for folder, save in bundles if save.content_hash]
uncached = [(folder, save) for folder, save in bundles if not save.content_hash]
results = await sync_handler.cached_md5s(
results = await sync_handler.cached_hashes(
[
(_member_md5s_cache_key(save), partial(_member_md5s_json, save))
for _, save in cached

View File

@@ -283,11 +283,10 @@ def _decoded(value: str | bytes | None) -> str | None:
return value or None
async def cached_md5s(
async def cached_hashes(
jobs: Sequence[tuple[str, Callable[[], Awaitable[str | None]]]],
) -> list[str | None]:
"""Each `(cache key, compute)` job's MD5, reading the cache in one MGET and
writing the misses back in one pipeline."""
"""Each `(cache key, compute)` job's hash, read in one MGET with misses written back in one pipeline."""
if not jobs:
return []
@@ -336,7 +335,7 @@ async def build_blob_manifest_entries(user: User) -> list[dict[str, str]]:
)
)
digests = await cached_md5s(jobs)
digests = await cached_hashes(jobs)
return [
{"path": blob_path, "hash": digest}
for blob_path, digest in zip(blob_paths, digests, strict=True)
@@ -389,7 +388,7 @@ async def asset_md5s(
assets: Sequence[Save | State | Screenshot],
) -> list[str | None]:
"""Each asset's MD5, or None when unreadable; a vanished file flags its row."""
return await cached_md5s(
return await cached_hashes(
[
(
f"romm:retroarch_sync:md5:{asset.full_path}"

View File

@@ -7,7 +7,7 @@ import pytest
from handler.filesystem.retroarch_sync_handler import BlobFile, FSRetroArchSyncHandler
from handler.redis_handler import async_cache, sync_cache
from handler.sync.retroarch.sync_handler import HASH_CACHE_TTL_SECONDS, cached_md5s
from handler.sync.retroarch.sync_handler import HASH_CACHE_TTL_SECONDS, cached_hashes
@pytest.fixture(autouse=True)
@@ -19,7 +19,7 @@ def _clear_cache() -> Iterator[None]:
class TestCachedMd5s:
async def test_misses_are_written_back_with_the_ttl(self):
await cached_md5s([("miss", mock.AsyncMock(return_value="fresh-md5"))])
await cached_hashes([("miss", mock.AsyncMock(return_value="fresh-md5"))])
assert await async_cache.get("miss") == b"fresh-md5"
ttl = await async_cache.ttl("miss")
@@ -33,18 +33,18 @@ class TestCachedMd5s:
("c", mock.AsyncMock(return_value=None)),
]
assert await cached_md5s(jobs) == ["fresh-a", "cached-b", None]
assert await cached_hashes(jobs) == ["fresh-a", "cached-b", None]
jobs[1][1].assert_not_awaited()
async def test_unreadable_files_are_not_cached(self):
await cached_md5s([("gone", mock.AsyncMock(return_value=None))])
await cached_hashes([("gone", mock.AsyncMock(return_value=None))])
assert await async_cache.exists("gone") == 0
async def test_reads_the_cache_in_one_round_trip(self):
jobs = [(f"key{i}", mock.AsyncMock(return_value=f"md5-{i}")) for i in range(5)]
with mock.patch.object(async_cache, "mget", wraps=async_cache.mget) as mget:
await cached_md5s(jobs)
await cached_hashes(jobs)
mget.assert_called_once()