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 {