diff --git a/src/app.html b/src/app.html index ec070ff769d55d660d9bb21136e4ab81b553ed7b..fba6fdb31aacd88cb6b0cd7d9fd030ed82f31276 100644 --- a/src/app.html +++ b/src/app.html @@ -2,7 +2,6 @@ <html lang="fr" class="h-full"> <head> <meta charset="utf-8" /> - <link rel="icon" href="%sveltekit.assets%/favicon.png" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" /> diff --git a/src/lib/data.ts b/src/lib/data.ts index 2e536e0fa7b4b74794045ee561040c413602fa1b..b4db74a3317d90d68e3d7e715fb5261e76aca724 100644 --- a/src/lib/data.ts +++ b/src/lib/data.ts @@ -12,7 +12,8 @@ const cache = new Map<number, PromoCache>(); // 1 hour const CACHE_DURATION_MS = 1000 * 60 * 60; -async function cacheImages(users: UserId[]): Promise<void> { +async function cacheImages(users: Iterable<UserId>): Promise<void> { + let count = 0; for (const user of users) { const response = await client.query(USER_DETAILS_QUERY, { idList: [user] }); @@ -23,17 +24,22 @@ async function cacheImages(users: UserId[]): Promise<void> { const photo = response.data?.page.nodes[0].photo; if (!photo?.url) continue; await fetch(photo.url, { method: "HEAD" }); + count++; } - console.log("cached", users.length, "images"); + console.log("cached", count, "images"); +} + +// background task +async function cachePromotionImages(year: number) { + const promo = cache.get(year); + if (!promo) return; + await cacheImages(promo.promotion); } async function fetchPromotion(year: number): Promise<PromoCache> { const array = await Array.fromAsync(pageIterator(PROMOTION_QUERY, { year })); const users = array.map((node) => node.id); - // background task - cacheImages(users); - return { lastUpdateMs: new Date().getTime(), promotion: new Set(users), @@ -49,6 +55,7 @@ export async function getPromotion(year: number): Promise<Set<UserId>> { console.log("year", year, "not in cache, fetching"); const freshData = await fetchPromotion(year); cache.set(year, freshData); + cachePromotionImages(year); return freshData.promotion; } @@ -70,3 +77,9 @@ export function getPromotionRange( (array) => new Set(array), ); } + +setInterval(() => { + for (const year of cache.keys()) { + cachePromotionImages(year); + } +}, CACHE_DURATION_MS / 2); diff --git a/src/routes/quiz/+page.server.ts b/src/routes/quiz/+page.server.ts index 90b3993d99f4c0ac08c25628584dc46740cb0c55..933b6e271310857850c779fccde98df0c968040c 100644 --- a/src/routes/quiz/+page.server.ts +++ b/src/routes/quiz/+page.server.ts @@ -66,7 +66,7 @@ export async function load(event) { } const MAX_POINTS = 10; -const MIN_POINTS = 0; +const MIN_POINTS = 3; // Durée maximale pour obtenir le score maximal const SERVER_DELAY_MAX = 3; diff --git a/static/favicon.png b/static/favicon.png deleted file mode 100644 index 825b9e65af7c104cfb07089bb28659393b4f2097..0000000000000000000000000000000000000000 Binary files a/static/favicon.png and /dev/null differ