this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: enable cache

+36 -9
+18 -8
public/app.js
··· 118 118 window.lastRefreshTime = Date.now(); 119 119 120 120 // Keep a copy of the current stories for metrics calculation during loading 121 - const previousStories = allStories && allStories.length > 0 ? [...allStories] : null; 122 - 121 + const previousStories = 122 + allStories && allStories.length > 0 ? [...allStories] : null; 123 + 123 124 storyList.innerHTML = '<div class="loading">Loading stories...</div>'; 124 125 125 126 // Ensure live counters are running ··· 255 256 // Apply filters and update UI 256 257 function applyFiltersAndUpdateUI(fallbackStories = null) { 257 258 // Use fallbackStories for metrics if current stories are empty 258 - const storiesForMetrics = (!allStories || allStories.length === 0) ? 259 - fallbackStories : allStories; 260 - 259 + const storiesForMetrics = 260 + !allStories || allStories.length === 0 ? fallbackStories : allStories; 261 + 261 262 if (!allStories || allStories.length === 0) { 262 263 if (!fallbackStories) return; 263 264 // If we have no current stories but have fallback, only update metrics ··· 563 564 if (!stories || stories.length === 0) { 564 565 // Don't reset values to zero if they already have values 565 566 // This prevents flickering during refresh operations 566 - if (topTenCountEl.textContent === "0" || topTenCountEl.textContent === "") { 567 + if ( 568 + topTenCountEl.textContent === "0" || 569 + topTenCountEl.textContent === "" 570 + ) { 567 571 topTenCountEl.textContent = "0"; 568 572 } 569 - if (mostActiveTimeEl.textContent === "N/A" || mostActiveTimeEl.textContent === "") { 573 + if ( 574 + mostActiveTimeEl.textContent === "N/A" || 575 + mostActiveTimeEl.textContent === "" 576 + ) { 570 577 mostActiveTimeEl.textContent = "N/A"; 571 578 } 572 - if (avgFrontpageTimeEl.textContent === "N/A" || avgFrontpageTimeEl.textContent === "") { 579 + if ( 580 + avgFrontpageTimeEl.textContent === "N/A" || 581 + avgFrontpageTimeEl.textContent === "" 582 + ) { 573 583 avgFrontpageTimeEl.textContent = "N/A"; 574 584 } 575 585 return;
+3 -1
src/index.ts
··· 147 147 let timeOnFrontPage = null; 148 148 if (story.enteredLeaderboardAt) { 149 149 // Use current time as end time if the story is still on the leaderboard 150 - const endTime = story.isOnLeaderboard ? Math.floor(Date.now() / 1000) : story.enteredLeaderboardAt + 3600; 150 + const endTime = story.isOnLeaderboard 151 + ? Math.floor(Date.now() / 1000) 152 + : story.enteredLeaderboardAt + 3600; 151 153 timeOnFrontPage = endTime - story.enteredLeaderboardAt; 152 154 } 153 155
+15
src/libs/cache.ts
··· 649 649 const requestStart = isProduction ? 0 : performance.now(); 650 650 651 651 try { 652 + // Check client ETag before executing query 653 + const clientETag = request.headers.get("if-none-match"); 654 + const cacheHeaders = createCacheHeaders(cacheKey, ttl); 655 + 656 + // If client ETag matches, return 304 657 + if (clientETag && clientETag === cacheHeaders.ETag) { 658 + return new Response(null, { 659 + status: 304, 660 + headers: { 661 + ETag: cacheHeaders.ETag, 662 + "Cache-Control": cacheHeaders["Cache-Control"] as string, 663 + }, 664 + }); 665 + } 666 + 652 667 // Get data from cache or execute query 653 668 const data = await queryCache.get(cacheKey, queryFn, ttl); 654 669