feat(provenance): ArtistService resolves images via artist_id

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 21:34:30 -04:00
parent 914cf14d9e
commit aaf5d1ea70
2 changed files with 26 additions and 14 deletions
+4 -14
View File
@@ -47,18 +47,12 @@ class ArtistService:
aid = artist.id
img_join = (
select(ImageRecord.id)
.join(ImageProvenance, ImageProvenance.image_record_id == ImageRecord.id)
.join(Source, Source.id == ImageProvenance.source_id)
.where(Source.artist_id == aid)
select(ImageRecord.id).where(ImageRecord.artist_id == aid)
)
image_count = (
await self.session.execute(
select(func.count(func.distinct(ImageRecord.id)))
.select_from(ImageRecord)
.join(ImageProvenance, ImageProvenance.image_record_id == ImageRecord.id)
.join(Source, Source.id == ImageProvenance.source_id)
.where(Source.artist_id == aid)
select(func.count(ImageRecord.id))
.where(ImageRecord.artist_id == aid)
)
).scalar_one()
@@ -162,11 +156,7 @@ class ArtistService:
# over ImageRecord fails in Postgres because its json columns have
# no equality operator.
stmt = select(ImageRecord).where(
ImageRecord.id.in_(
select(ImageProvenance.image_record_id)
.join(Source, Source.id == ImageProvenance.source_id)
.where(Source.artist_id == artist.id)
)
ImageRecord.artist_id == artist.id
)
if cursor:
cur_ts, cur_id = decode_cursor(cursor)
+22
View File
@@ -82,3 +82,25 @@ async def test_paged_images(db):
async def test_paged_images_unknown_slug_none(db):
svc = ArtistService(db)
assert await svc.images("ghost", cursor=None, limit=10) is None
@pytest.mark.asyncio
async def test_overview_and_images_include_artist_id_only(db):
# FC-2d-vii-c: a folder-style image has artist_id but no provenance.
a = Artist(name="Solo", slug="solo")
db.add(a)
await db.flush()
rec = ImageRecord(
path="/images/s/1.jpg", sha256="s" + "0" * 63,
size_bytes=1, mime="image/jpeg", width=1, height=1,
origin="imported_filesystem", integrity_status="unknown",
artist_id=a.id,
)
db.add(rec)
await db.flush()
svc = ArtistService(db)
ov = await svc.overview("solo")
assert ov["image_count"] == 1
page = await svc.images("solo", cursor=None, limit=10)
assert [i["id"] for i in page.images] == [rec.id]