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
This commit is contained in:
parent
31c6135f5d
commit
4257b65ab5
@ -987,10 +987,19 @@ class BunnyStorage implements IStorage {
|
||||
}
|
||||
|
||||
async updateVideoViews(id: string): Promise<void> {
|
||||
// Since we can't update views in Bunny.net directly, we'll cache them locally
|
||||
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<number> {
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user