RECORDGOD/app/mirror.py
type-two 9b8ecdb84d feat: deploy-ready — env-aware Discogs enrichment + Dockerfile
- app/mirror.py: centralised enrichment, DISCOGS_MIRROR_KIND selects full (ultra `release`)
  vs vps (`discogs_release`); virtual.py + wowplatter_v1.py use it.
- Dockerfile + .dockerignore for the VPS container.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 13:08:49 +10:00

32 lines
1.2 KiB
Python

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 {}