diff --git a/src/routes/heatmap/+page.svelte b/src/routes/heatmap/+page.svelte index 65c51f12..33345d36 100644 --- a/src/routes/heatmap/+page.svelte +++ b/src/routes/heatmap/+page.svelte @@ -2,6 +2,8 @@ import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; import { Button } from "$lib/components/shadcn/button/index.js"; import SEO from "$lib/components/SEO.svelte"; + import { setCache, getCache } from "$lib/store"; + import { onDestroy } from "svelte"; export let data; let rawData = data?.getData; @@ -9,19 +11,28 @@ let iframeLoaded = false; let selectedFormat: "png" | "jpeg" | "svg" = "png"; let selectedTimePeriod = "1D"; - let isLoaded = false; + let iframeUrl: string; async function getHeatMap() { - const postData = { params: selectedTimePeriod }; - const response = await fetch("/api/heatmap", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); + const cachedData = getCache(selectedTimePeriod, "getHeatmap"); + if (cachedData) { + rawData = cachedData; + } else { + const postData = { params: selectedTimePeriod }; + const response = await fetch("/api/heatmap", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(postData), + }); - rawData = await response.json(); + rawData = await response.json(); + setCache(selectedTimePeriod, rawData, "getHeatmap"); + } + + const blob = new Blob([rawData], { type: "text/html" }); + iframeUrl = URL.createObjectURL(blob); } async function downloadPlot(item) { @@ -68,15 +79,23 @@ } } + onDestroy(() => { + if (iframeUrl) URL.revokeObjectURL(iframeUrl); + }); + $: { if (selectedTimePeriod && typeof window !== "undefined") { - isLoaded = false; - getHeatMap(); - isLoaded = true; + (async () => { + await getHeatMap(); + })(); } } + + + + (iframeLoaded = true)} /> diff --git a/src/routes/stocks/[tickerID]/profile/+page.svelte b/src/routes/stocks/[tickerID]/profile/+page.svelte index 9cea09ac..a7bad2ca 100644 --- a/src/routes/stocks/[tickerID]/profile/+page.svelte +++ b/src/routes/stocks/[tickerID]/profile/+page.svelte @@ -174,7 +174,7 @@ ${paragraphs.join("\n")} {rawData?.fullTimeEmployees ? new Intl.NumberFormat("en")?.format( rawData?.fullTimeEmployees,