← back to AsSeenInMovies
asseeninmovies: /api/health perf — pull counts from _homeCache instead of running count(*) on 290k rows per request. 505ms → 1.6ms warm. Returns null counts + as_of=null on cold-cache (request fires before warmup completes); SELECT 1 liveness stays no matter what.
592a2e77fea8838ea84bf912b2996ae5df625962 · 2026-05-12 19:07:26 -0700 · SteveStudio2
Files touched
Diff
commit 592a2e77fea8838ea84bf912b2996ae5df625962
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date: Tue May 12 19:07:26 2026 -0700
asseeninmovies: /api/health perf — pull counts from _homeCache instead of running count(*) on 290k rows per request. 505ms → 1.6ms warm. Returns null counts + as_of=null on cold-cache (request fires before warmup completes); SELECT 1 liveness stays no matter what.
---
server.js | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/server.js b/server.js
index 9a8239b..53fd4d5 100644
--- a/server.js
+++ b/server.js
@@ -61,15 +61,20 @@ app.use(express.static(path.join(__dirname, 'public'), { maxAge: '1h' }));
app.get('/api/health', async (_req, res) => {
try {
+ // Cheap liveness: SELECT 1 only. The count(*) counts come from the
+ // home cache (60s SWR), so /api/health stays sub-10ms regardless of
+ // table size. Was 500ms+ doing full count(*) on 290k rows.
const r = await pool.query('SELECT 1 AS ok');
- const counts = await pool.query(`
- SELECT
- (SELECT count(*) FROM asim_movies) AS movies,
- (SELECT count(*) FROM asim_people) AS people,
- (SELECT count(*) FROM asim_credits) AS credits,
- (SELECT count(*) FROM asim_spotted) AS spotted
- `).catch(() => ({ rows: [{ movies: 0, people: 0, credits: 0, spotted: 0 }] }));
- res.json({ ok: r.rows[0].ok === 1, counts: counts.rows[0] });
+ const stats = (_homeCache && _homeCache.data && _homeCache.data.stats) || null;
+ res.json({
+ ok: r.rows[0].ok === 1,
+ counts: stats ? {
+ movies: Number(stats.movies_total) || 0,
+ people: Number(stats.people_total) || 0,
+ spotted: Number(stats.spotted_total) || 0,
+ } : null,
+ as_of: stats && _homeCache.at ? new Date(_homeCache.at).toISOString() : null,
+ });
} catch (e) {
res.status(500).json({ ok: false, error: e.message });
}
← 1910794 asseeninmovies: /search perf — gate ILIKE search to poster/h
·
back to AsSeenInMovies
·
asseeninmovies: GET /random/movie and /random/person — 302 t b8cbc44 →