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:
@@ -46,6 +46,16 @@ class SqlAlchemyTrackRepository:
|
||||
row = await self._session.get(TrackModel, track_id)
|
||||
return _to_entity(row) if row is not None else None
|
||||
|
||||
async def get_many(self, ids: list[uuid.UUID]) -> list[Track]:
|
||||
if not ids:
|
||||
return []
|
||||
rows = (
|
||||
(await self._session.execute(select(TrackModel).where(TrackModel.id.in_(ids))))
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
return [_to_entity(r) for r in rows]
|
||||
|
||||
async def get_by_source(self, source: str, source_id: str) -> Track | None:
|
||||
row = (
|
||||
await self._session.execute(
|
||||
|
||||
Reference in New Issue
Block a user