perf(reco): batch id->entity hydration

radio/similar resolved ids one get_by_id at a time (N round-trips). Add
TrackRepository.get_many and use it (plus ArtistRepository.get_many) to
hydrate in a single query, preserving requested order.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Цвылев Александр Вадимович
2026-07-29 10:53:35 +03:00
parent ed77acf0fe
commit d16c6085c9
3 changed files with 21 additions and 4 deletions
+5
View File
@@ -142,6 +142,11 @@ class ArtistRepository(Protocol):
class TrackRepository(Protocol):
async def get_by_id(self, track_id: uuid.UUID) -> Track | None: ...
async def get_many(self, ids: list[uuid.UUID]) -> list[Track]:
"""Resolve multiple ids in one query (unordered) — batches the per-id
lookups radio/similar would otherwise fan out into N round-trips."""
...
async def get_by_source(self, source: str, source_id: str) -> Track | None: ...
async def add(
self,