Precharge les mappings IMDb au warmup (1.27s -> 16ms sur le premier appel /api?t=imdb)

This commit is contained in:
unfr
2026-04-24 07:47:23 +02:00
parent 4687b83cde
commit fbf99a9ccf
2 changed files with 15 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import secureSession from '@fastify/secure-session';
import fastifyStatic from '@fastify/static';
import Fastify from 'fastify';
import { HOST, PORT, RATE_LIMIT_PER_SEC, ROOT, SESSION_SECRET } from './config.js';
import { preloadMappings } from './lib/imdbMapping.js';
import { getRatings } from './lib/imdbRatings.js';
import { httpDuration, httpRequests, imdbRatingsCount, searchWorkers } from './lib/metrics.js';
import { getPool } from './lib/searchEngine.js';
@@ -80,7 +81,11 @@ fastify.ready().then(async () => {
const tv = getPool('tv');
searchWorkers.set({ type: 'movie' }, movie.workers.length);
searchWorkers.set({ type: 'tv' }, tv.workers.length);
fastify.log.info({ ratings: ratings.size }, 'Warmup complete');
const maps = await preloadMappings();
fastify.log.info(
{ ratings: ratings.size, imdb_movie: maps.movie, imdb_tv: maps.tv },
'Warmup complete',
);
} catch (err) {
fastify.log.warn({ err }, 'Warmup failed');
}