···118118 window.lastRefreshTime = Date.now();
119119120120 // Keep a copy of the current stories for metrics calculation during loading
121121- const previousStories = allStories && allStories.length > 0 ? [...allStories] : null;
122122-121121+ const previousStories =
122122+ allStories && allStories.length > 0 ? [...allStories] : null;
123123+123124 storyList.innerHTML = '<div class="loading">Loading stories...</div>';
124125125126 // Ensure live counters are running
···255256 // Apply filters and update UI
256257 function applyFiltersAndUpdateUI(fallbackStories = null) {
257258 // Use fallbackStories for metrics if current stories are empty
258258- const storiesForMetrics = (!allStories || allStories.length === 0) ?
259259- fallbackStories : allStories;
260260-259259+ const storiesForMetrics =
260260+ !allStories || allStories.length === 0 ? fallbackStories : allStories;
261261+261262 if (!allStories || allStories.length === 0) {
262263 if (!fallbackStories) return;
263264 // If we have no current stories but have fallback, only update metrics
···563564 if (!stories || stories.length === 0) {
564565 // Don't reset values to zero if they already have values
565566 // This prevents flickering during refresh operations
566566- if (topTenCountEl.textContent === "0" || topTenCountEl.textContent === "") {
567567+ if (
568568+ topTenCountEl.textContent === "0" ||
569569+ topTenCountEl.textContent === ""
570570+ ) {
567571 topTenCountEl.textContent = "0";
568572 }
569569- if (mostActiveTimeEl.textContent === "N/A" || mostActiveTimeEl.textContent === "") {
573573+ if (
574574+ mostActiveTimeEl.textContent === "N/A" ||
575575+ mostActiveTimeEl.textContent === ""
576576+ ) {
570577 mostActiveTimeEl.textContent = "N/A";
571578 }
572572- if (avgFrontpageTimeEl.textContent === "N/A" || avgFrontpageTimeEl.textContent === "") {
579579+ if (
580580+ avgFrontpageTimeEl.textContent === "N/A" ||
581581+ avgFrontpageTimeEl.textContent === ""
582582+ ) {
573583 avgFrontpageTimeEl.textContent = "N/A";
574584 }
575585 return;
+3-1
src/index.ts
···147147 let timeOnFrontPage = null;
148148 if (story.enteredLeaderboardAt) {
149149 // Use current time as end time if the story is still on the leaderboard
150150- const endTime = story.isOnLeaderboard ? Math.floor(Date.now() / 1000) : story.enteredLeaderboardAt + 3600;
150150+ const endTime = story.isOnLeaderboard
151151+ ? Math.floor(Date.now() / 1000)
152152+ : story.enteredLeaderboardAt + 3600;
151153 timeOnFrontPage = endTime - story.enteredLeaderboardAt;
152154 }
153155
+15
src/libs/cache.ts
···649649 const requestStart = isProduction ? 0 : performance.now();
650650651651 try {
652652+ // Check client ETag before executing query
653653+ const clientETag = request.headers.get("if-none-match");
654654+ const cacheHeaders = createCacheHeaders(cacheKey, ttl);
655655+656656+ // If client ETag matches, return 304
657657+ if (clientETag && clientETag === cacheHeaders.ETag) {
658658+ return new Response(null, {
659659+ status: 304,
660660+ headers: {
661661+ ETag: cacheHeaders.ETag,
662662+ "Cache-Control": cacheHeaders["Cache-Control"] as string,
663663+ },
664664+ });
665665+ }
666666+652667 // Get data from cache or execute query
653668 const data = await queryCache.get(cacheKey, queryFn, ttl);
654669