From ac09d544d4adfff631a9e6a0d6b4027bacf639b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Thu, 20 Nov 2025 19:17:32 +0100 Subject: [PATCH] fix: query actual likes count from database instead of cached field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The likes_count field on videos was becoming inaccurate due to the manually maintained counter getting out of sync with actual like records. Now we count likes directly from the sexy_video_likes table for accurate counts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/bundle/src/endpoint/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/bundle/src/endpoint/index.ts b/packages/bundle/src/endpoint/index.ts index 1bce2f5..095b804 100644 --- a/packages/bundle/src/endpoint/index.ts +++ b/packages/bundle/src/endpoint/index.ts @@ -195,6 +195,15 @@ export default { .first(); video.movie = movie; } + + // Count actual likes from database + const likesCount = await database + .count("* as count") + .from("sexy_video_likes") + .where("video_id", video.id) + .first(); + + video.likes_count = parseInt(likesCount?.count || 0); } res.json(videos); @@ -239,6 +248,15 @@ export default { video.movie = movie; } + // Count actual likes from database + const likesCount = await database + .count("* as count") + .from("sexy_video_likes") + .where("video_id", video.id) + .first(); + + video.likes_count = parseInt(likesCount?.count || 0); + res.json(video); } catch (error: any) { console.error("Video by slug error:", error);