Cache stars

This commit is contained in:
2024-09-28 01:28:50 +03:00
parent 041262d09b
commit 7f03065936
5 changed files with 32 additions and 40 deletions

View File

@@ -1,8 +1,23 @@
import type {PageServerLoad} from "./$types";
import getStars from "$lib/getStars";
let lastRequest = Date.now()
let starCount: number
export const load: PageServerLoad = async () => {
const now = Date.now()
const CACHE_LIFE = 1000 * 60 * 5
if (now - CACHE_LIFE > lastRequest || starCount === undefined) {
lastRequest = Date.now()
try {
starCount = await getStars('anatolykopyl')
} catch (error) {
console.log(error)
}
}
return {
starCount: await getStars('anatolykopyl')
starCount,
};
}

View File

@@ -73,10 +73,12 @@ const goTop = () => {
href="https://github.com/anatolykopyl"
>
<Github></Github>
<div class="rounded-lg text-sm border border-slate-200 border-opacity-50 px-2 bg-slate-500 bg-opacity-25 absolute bottom-0 w-max translate-y-full mb-1 flex gap-1 items-center">
{starCount}
<MaterialSymbolsStarRounded class="max-h-4 max-w-4" />
</div>
{#if starCount}
<div class="rounded-lg text-sm border border-slate-200 border-opacity-50 px-2 bg-slate-500 bg-opacity-25 absolute bottom-0 w-max translate-y-full mb-1 flex gap-1 items-center">
{starCount}
<MaterialSymbolsStarRounded class="max-h-4 max-w-4" />
</div>
{/if}
</a>
<a
class="hero__social-icon"