import type {PageServerLoad} from "./$types";
import getStars from "$lib/getStars";

const CACHE_LIFE = 1000 * 60 * 5

let lastRequest = Date.now()
let starCount: number | null = null

export const load: PageServerLoad = async () => {
  const now = Date.now()

  if (now - CACHE_LIFE > lastRequest || starCount === null) {
    lastRequest = Date.now()
    try {
      starCount = await getStars('anatolykopyl')
    } catch (error) {
      console.log(error)
    }
  }

  return {
    starCount,
  };
}
