[object Object]

← back to AsSeenInMovies

asseeninmovies: GET /api/credits/stats — aggregate counts on asim_credits (363k rows). 5min Cache-Control+SWR. /api discovery doc updated. 67/67.

08a8678cea72830e2c8194a4799580154757b613 · 2026-05-13 08:02:35 -0700 · SteveStudio2

Files touched

Diff

commit 08a8678cea72830e2c8194a4799580154757b613
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Wed May 13 08:02:35 2026 -0700

    asseeninmovies: GET /api/credits/stats — aggregate counts on asim_credits (363k rows). 5min Cache-Control+SWR. /api discovery doc updated. 67/67.
---
 server.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/server.js b/server.js
index 8afea8d..2fbcf7d 100644
--- a/server.js
+++ b/server.js
@@ -94,6 +94,7 @@ app.get('/api', (_req, res) => {
       'GET /api/spotted/random': 'A single random verified SPOTTED placement (with movie context)',
       'GET /api/movies/random':  'A single random poster-having movie',
       'GET /api/people/random':  'A single random headshot-having person',
+      'GET /api/credits/stats':  'Aggregate counts on asim_credits (total, acting, directing, writing, distinct_people, distinct_movies)',
       'GET /api/ingest/status':  'Background-ingest queue depth (admin-ish; safe to expose)',
     },
     public_data_only: true,
@@ -770,6 +771,32 @@ app.get('/api/spotted/random', async (_req, res) => {
   }
 });
 
+// /api/credits/stats — aggregate counts on asim_credits. Departments, actors
+// vs crew, top contributors. Cached 5 min (363k rows is heavy to recount).
+app.get('/api/credits/stats', async (_req, res) => {
+  try {
+    res.setHeader('Cache-Control', 'public, max-age=300, stale-while-revalidate=600');
+    const r = await pool.query(`
+      SELECT
+        (SELECT count(*) FROM asim_credits)                                                AS total,
+        (SELECT count(*) FROM asim_credits WHERE department='Acting')                      AS acting,
+        (SELECT count(*) FROM asim_credits WHERE department='Directing')                   AS directing,
+        (SELECT count(*) FROM asim_credits WHERE department='Writing')                     AS writing,
+        (SELECT count(DISTINCT person_id) FROM asim_credits)                               AS distinct_people,
+        (SELECT count(DISTINCT movie_id) FROM asim_credits)                                AS distinct_movies`);
+    const row = r.rows[0] || {};
+    res.json({
+      total:           Number(row.total || 0),
+      acting:          Number(row.acting || 0),
+      directing:       Number(row.directing || 0),
+      writing:         Number(row.writing || 0),
+      distinct_people: Number(row.distinct_people || 0),
+      distinct_movies: Number(row.distinct_movies || 0),
+      as_of:           new Date().toISOString(),
+    });
+  } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
 app.get('/api/spotted/stats', async (_req, res) => {
   // Short Cache-Control — stats don't change second-to-second. 30s lets
   // crawlers/dashboards/status-loop poll without hammering pg.

← f7d2a51 asim /api/health Cache-Control: no-store (timestamped livene  ·  back to AsSeenInMovies  ·  asim smoke +2 /api/credits/stats checks. 69/69. a43054b →