feat(artist): post_count on the artist overview response — drives the Posts/Gallery default-tab fallback in the upcoming ArtistView redesign

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 15:59:28 -04:00
parent 992f38ec20
commit 2e8d7c960c
2 changed files with 34 additions and 0 deletions
+10
View File
@@ -111,12 +111,22 @@ class ArtistService:
)
).all()
post_count = (
await self.session.execute(
select(func.count(func.distinct(Post.id)))
.select_from(Post)
.join(Source, Source.id == Post.source_id)
.where(Source.artist_id == aid)
)
).scalar_one()
return {
"id": artist.id,
"name": artist.name,
"slug": artist.slug,
"is_subscription": bool(artist.is_subscription),
"image_count": int(image_count),
"post_count": int(post_count),
"date_range": {
"min": dmin.isoformat() if dmin else None,
"max": dmax.isoformat() if dmax else None,
+24
View File
@@ -29,6 +29,30 @@ async def test_artist_overview_ok(client, db):
body = await resp.get_json()
assert body["name"] == "Mira"
assert body["image_count"] == 0
assert body["post_count"] == 0
@pytest.mark.asyncio
async def test_artist_overview_post_count(client, db):
from backend.app.models import Post, Source
a = Artist(name="Lyra", slug="lyra")
db.add(a)
await db.flush()
s = Source(
artist_id=a.id, platform="patreon",
url="https://patreon.com/cw/lyra", enabled=True,
)
db.add(s)
await db.flush()
db.add(Post(source_id=s.id, external_post_id="p1"))
db.add(Post(source_id=s.id, external_post_id="p2"))
await db.flush()
await db.commit()
resp = await client.get("/api/artist/lyra")
assert resp.status_code == 200
body = await resp.get_json()
assert body["post_count"] == 2
@pytest.mark.asyncio