Cache stars
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user