import os from sqlalchemy import text from .db import MirrorSession # Enrichment from the Discogs mirror. Two known shapes, selected by env so the same code runs # on ultra (the full dump) and on the VPS (dealgod's discogs_release subset): # full → table `release` cols artists_sort / thumb / estimated_weight (ultra) # vps → table `discogs_release` cols artist (no cover/weight) (dealgod-db) KIND = os.getenv("DISCOGS_MIRROR_KIND", "full") if KIND == "vps": _SQL = ("SELECT id, title, artist, NULL::text AS thumb, NULL::int AS weight " "FROM discogs_release WHERE id = ANY(:ids)") else: _SQL = ("SELECT id, title, artists_sort AS artist, " "COALESCE(thumb_local_url, thumb) AS thumb, estimated_weight AS weight " "FROM release WHERE id = ANY(:ids)") async def enrich(ids): """release_id(s) → {id: {title, artist, thumb, weight}}. Best-effort: mirror down → {}.""" ids = [i for i in set(ids) if i is not None] if not ids: return {} try: async with MirrorSession() as m: rows = await m.execute(text(_SQL), {"ids": ids}) return {r["id"]: dict(r) for r in rows.mappings()} except Exception: return {}