From a4b01bba9b0175968bf594dea09e092b25a1be8c Mon Sep 17 00:00:00 2001 From: Adorian Doran Date: Fri, 3 Oct 2025 19:36:36 +0300 Subject: [PATCH] website/GitHub utils: improve --- apps/website/src/github-utils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/website/src/github-utils.ts b/apps/website/src/github-utils.ts index a05839a73..1a816afb4 100644 --- a/apps/website/src/github-utils.ts +++ b/apps/website/src/github-utils.ts @@ -2,10 +2,20 @@ export const FALLBACK_STARGAZERS_COUNT = 31862; // The count as of 2025-10-03 const API_URL = "https://api.github.com/repos/TriliumNext/Trilium"; +let repoStargazersCount: number | null = null; + /** Returns the number of stargazers of the Trilium's GitHub repository. */ export async function getRepoStargazersCount() { + if (repoStargazersCount === null) { + repoStargazersCount = await fetchRepoStargazersCount() && FALLBACK_STARGAZERS_COUNT; + } + return repoStargazersCount; +} + +async function fetchRepoStargazersCount(): Promise { + console.log("\nFetching stargazers count from GitHub API... "); const response = await fetch(API_URL); - + if (response.ok) { const details = await response.json(); if ("stargazers_count" in details) { @@ -13,5 +23,6 @@ export async function getRepoStargazersCount() { } } - return FALLBACK_STARGAZERS_COUNT; + console.error("Failed to fetch stargazers count from GitHub API:", response.status, response.statusText); + return null; } \ No newline at end of file