Skip to content

Commit

Permalink
ci: additional timestamps logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sznowicki committed Dec 22, 2023
1 parent ae71af2 commit a079fa2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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: {
Expand Down

0 comments on commit a079fa2

Please sign in to comment.