diff --git a/functions/index.js b/functions/index.js index f529e05..84e4166 100644 --- a/functions/index.js +++ b/functions/index.js @@ -7,17 +7,21 @@ import {emitPageView} from '../lib/plausible.js'; import {parseQuery} from '../lib/parseQuery.js'; export const onRequestGet = async (context) => { - const timestamp = Date.now(); + const startTime = Date.now(); const { request, env } = context; const { searchParams } = new URL(request.url); const { q} = Object.fromEntries(searchParams.entries()); const { q: searchQuery, lang } = parseQuery(q); - const startTime = Date.now(); + const searchTimeStamp = Date.now(); const result = q ? await search(env, searchQuery, lang) : null; - const doneIn = Date.now() - startTime; + const doneIn = Date.now() - searchTimeStamp; + console.log(`Result milestone took ${Date.now() - startTime}ms`); + const viewDefaults = await getDefaultViewData(env); + console.log(`Default view milestone took ${Date.now() - startTime}ms`); + const hasBlogs = result?.hits.blogs.length > 0; const hasDocs = result?.hits.docs.length > 0; const hasMagazines = result?.hits.magazines.length > 0; @@ -50,6 +54,8 @@ export const onRequestGet = async (context) => { '--has-query': hasQuery, }); + console.log(`Processing results milestone took ${Date.now() - startTime}ms`); + const hasResults = hasQuery ? results.length > 0 : undefined; // without await it might get killed before sending by cloudflare @@ -58,6 +64,9 @@ export const onRequestGet = async (context) => { }); const facets = await getFacets(env); + + console.log(`Facets milestone took ${Date.now() - startTime}ms`); + const langs = [...facets.lang.values()].sort((a,b) => a.count > b.count ? -1 : 1); // Save used queries for analytics @@ -83,8 +92,7 @@ export const onRequestGet = async (context) => { }; const html = Mustache.render(template, view); - - console.log(`Processing took ${Date.now() - timestamp}ms`); + console.log(`Last milestone took ${Date.now() - startTime}ms`); return new Response(html, { headers: {