···133133 by: true,
134134 enteredLeaderboardAt: true,
135135 firstSeenAt: true,
136136- lastSeenOnLeaderboardAt: true,
136136+ isOnLeaderboard: true,
137137 isFromMonitoredUser: true,
138138 },
139139 where: (stories, { eq }) => eq(stories.id, storyId),
···145145146146 // Calculate time on front page if available
147147 let timeOnFrontPage = null;
148148- if (story.enteredLeaderboardAt && story.lastSeenOnLeaderboardAt) {
149149- timeOnFrontPage =
150150- story.lastSeenOnLeaderboardAt - story.enteredLeaderboardAt;
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;
151151+ timeOnFrontPage = endTime - story.enteredLeaderboardAt;
151152 }
152153153154 // Format the response
···332333333334 "/api/story/:id/snapshots": handleCORS(async (req) => {
334335 try {
335335- // Extract the story ID from the URL path using faster string operations
336336+ // Extract the story ID from the URL path
336337 const url = new URL(req.url);
337338 const pathParts = url.pathname.split("/");
338339 const storyIdStr = pathParts[3]; // Get ID from path parts directly