← back to AsSeenInMovies
asseeninmovies: home page perf — parallelize 4 queries via Promise.all (3.9s sequential → ~100ms warm); rejected TABLESAMPLE due to cold-cache cost + empty samples on filtered WHERE
25508fb50cbdba6f2ddb51e48e98ce3d809e7dad · 2026-05-12 17:13:38 -0700 · SteveStudio2
Files touched
Diff
commit 25508fb50cbdba6f2ddb51e48e98ce3d809e7dad
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date: Tue May 12 17:13:38 2026 -0700
asseeninmovies: home page perf — parallelize 4 queries via Promise.all (3.9s sequential → ~100ms warm); rejected TABLESAMPLE due to cold-cache cost + empty samples on filtered WHERE
---
server.js | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/server.js b/server.js
index c50f16e..affe258 100644
--- a/server.js
+++ b/server.js
@@ -1228,24 +1228,32 @@ app.get('/', async (_req, res) => {
let stats = { movies_total: 0, people_total: 0, movies_poster: 0, people_headshot: 0, spotted_total: 0 };
let featuredMovies = [], featuredPeople = [], featuredSpotted = [];
try {
- const s = await pool.query(`
- SELECT
- (SELECT count(*) FROM asim_movies) AS movies_total,
- (SELECT count(*) FROM asim_movies WHERE poster_url IS NOT NULL) AS movies_poster,
- (SELECT count(*) FROM asim_people) AS people_total,
- (SELECT count(*) FROM asim_people WHERE headshot_url IS NOT NULL) AS people_headshot,
- (SELECT count(*) FROM asim_spotted WHERE verified_at IS NOT NULL AND (verified_by IS NULL OR verified_by NOT LIKE 'rejected%')) AS spotted_total`);
+ // Parallel via Promise.all so the home page wall time = max of the four
+ // queries instead of sum. count(*) on asim_movies/asim_people is the
+ // long-pole at ~3s cold; running the featured-rail picks alongside (not
+ // after) cuts total home-page time roughly in half. Kept ORDER BY
+ // random() since TABLESAMPLE SYSTEM had 3s startup AND produced empty
+ // samples when paired with a restrictive WHERE.
+ const [s, fm, fp, fs] = await Promise.all([
+ pool.query(`
+ SELECT
+ (SELECT count(*) FROM asim_movies) AS movies_total,
+ (SELECT count(*) FROM asim_movies WHERE poster_url IS NOT NULL) AS movies_poster,
+ (SELECT count(*) FROM asim_people) AS people_total,
+ (SELECT count(*) FROM asim_people WHERE headshot_url IS NOT NULL) AS people_headshot,
+ (SELECT count(*) FROM asim_spotted WHERE verified_at IS NOT NULL AND (verified_by IS NULL OR verified_by NOT LIKE 'rejected%')) AS spotted_total`),
+ pool.query(`SELECT id, title, release_year, poster_url FROM asim_movies WHERE poster_url IS NOT NULL ORDER BY random() LIMIT 6`),
+ pool.query(`SELECT id, full_name, headshot_url, primary_profession FROM asim_people WHERE headshot_url IS NOT NULL ORDER BY random() LIMIT 6`),
+ pool.query(`
+ SELECT s.id AS spot_id, s.product_name, s.product_category, s.brand, s.scene_timecode,
+ m.id AS movie_id, m.title, m.release_year, m.poster_url, m.poster_source
+ FROM asim_spotted s JOIN asim_movies m ON m.id = s.movie_id
+ WHERE s.verified_at IS NOT NULL AND (verified_by IS NULL OR verified_by NOT LIKE 'rejected%')
+ ORDER BY s.verified_at DESC LIMIT 6`)
+ ]);
stats = s.rows[0];
- const fm = await pool.query(`SELECT id, title, release_year, poster_url FROM asim_movies WHERE poster_url IS NOT NULL ORDER BY random() LIMIT 6`);
featuredMovies = fm.rows;
- const fp = await pool.query(`SELECT id, full_name, headshot_url, primary_profession FROM asim_people WHERE headshot_url IS NOT NULL ORDER BY random() LIMIT 6`);
featuredPeople = fp.rows;
- const fs = await pool.query(`
- SELECT s.id AS spot_id, s.product_name, s.product_category, s.brand, s.scene_timecode,
- m.id AS movie_id, m.title, m.release_year, m.poster_url, m.poster_source
- FROM asim_spotted s JOIN asim_movies m ON m.id = s.movie_id
- WHERE s.verified_at IS NOT NULL AND (verified_by IS NULL OR verified_by NOT LIKE 'rejected%')
- ORDER BY s.verified_at DESC LIMIT 6`);
featuredSpotted = fs.rows;
} catch (e) {
// home page should never 500; fall back to static.
← 17d9d2d asseeninmovies: /spotted gallery — 4-tile stats strip (place
·
back to AsSeenInMovies
·
asseeninmovies: home page — 60s in-memory cache with infligh d6451f3 →