Skip to content

Commit

Permalink
fix(searchbad): stats
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed May 14, 2024
1 parent afe67b8 commit 64b98cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/routes/searchbad/+page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function getCategory(query, params) {

/** @type {import('./$types').PageLoad} */
export async function load({ url, fetch }) {
const renderStart = Date.now();

// Get query, current page, and max pages from URL
const query = url.searchParams.get('q') ?? '';
const currentPage = parseInt(url.searchParams.get('start') ?? '1', 10);
Expand Down Expand Up @@ -73,9 +75,9 @@ export async function load({ url, fetch }) {
});

// Fetch results
const timerStart = Date.now();
const fetchStart = Date.now();
const results = await fetchResults(newSearchParams, fetch);
const timerEnd = Date.now();
const fetchEnd = Date.now();

return {
browser: browser,
Expand All @@ -84,6 +86,15 @@ export async function load({ url, fetch }) {
maxPages: maxPages,
category: category,
results: results,
timing: timerEnd - timerStart
timing: {
render: {
start: renderStart,
end: Date.now()
},
api: {
start: fetchStart,
end: fetchEnd
}
}
};
}
5 changes: 3 additions & 2 deletions src/routes/searchbad/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
// const maxPages = $derived(data.maxPages);
const category = $derived(data.category);
const results = $derived(data.results);
const timing = $derived(data.timing);
const timingRender = $derived(data.timing.render.end - data.timing.render.start);
const timingApi = $derived(data.timing.api.end - data.timing.api.start);
/** @type {ResultType | undefined} */
let imagePreview = $state(undefined);
Expand All @@ -40,7 +41,7 @@

<Header bind:query {category} />
{#if results.length !== 0}
<Stats numOfResults={results.length} {timing} />
<Stats numOfResults={results.length} {timingRender} {timingApi} />
{/if}

{#if results.length === 0}
Expand Down

0 comments on commit 64b98cd

Please sign in to comment.