From 4257b65ab53f9215031528951f1568dfd8048e4e Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Sun, 11 Jan 2026 09:21:23 +0000 Subject: [PATCH] Update video view counts to be stored persistently Modify the video view count update mechanism to persist increments to the PostgreSQL database, falling back to a memory cache on failure. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 401e2ec0-e00d-4f10-9d0e-60f3d479f9a5 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: f07113b3-e389-43cd-b440-5132a7de4c57 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/60d372ff-2c10-46c7-b01b-10c3435136b0/401e2ec0-e00d-4f10-9d0e-60f3d479f9a5/1EjgdCg --- server/storage.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/storage.ts b/server/storage.ts index c272fca..83e5e9e 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -987,9 +987,18 @@ class BunnyStorage implements IStorage { } async updateVideoViews(id: string): Promise { - // Since we can't update views in Bunny.net directly, we'll cache them locally - const currentViews = this.viewsCache.get(id) || 0; - this.viewsCache.set(id, currentViews + 1); + try { + // Persist view count increment to PostgreSQL database + await db.update(videos) + .set({ views: sql`${videos.views} + 1` }) + .where(eq(videos.id, id)); + console.log(`✅ View count incremented for video ${id} in database`); + } catch (error) { + console.error(`❌ Failed to update view count for video ${id}:`, error); + // Fallback to memory cache if database fails + const currentViews = this.viewsCache.get(id) || 0; + this.viewsCache.set(id, currentViews + 1); + } } async getVideoCount(search?: string): Promise {