Simplify video view tracking to rely solely on CDN
Remove local view caching and database update logic, now using CDN-provided view counts. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 401e2ec0-e00d-4f10-9d0e-60f3d479f9a5 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 96faccf6-c704-4d5c-9214-e2d98ff0726c 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
4257b65ab5
commit
9f991a203a
@ -788,7 +788,6 @@ export class MemStorage implements IStorage {
|
|||||||
// Use Bunny.net storage if API keys are available, otherwise fallback to memory storage
|
// Use Bunny.net storage if API keys are available, otherwise fallback to memory storage
|
||||||
class BunnyStorage implements IStorage {
|
class BunnyStorage implements IStorage {
|
||||||
private bunnyService: BunnyService;
|
private bunnyService: BunnyService;
|
||||||
private viewsCache: Map<string, number> = new Map();
|
|
||||||
private faceDataCache: Map<string, { faceCenterPosition?: string; facesDetected?: number; faceConfidence?: number }> = new Map();
|
private faceDataCache: Map<string, { faceCenterPosition?: string; facesDetected?: number; faceConfidence?: number }> = new Map();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -811,11 +810,6 @@ class BunnyStorage implements IStorage {
|
|||||||
// Try cache first for faster loading
|
// Try cache first for faster loading
|
||||||
const cachedVideo = videoSyncService.getVideos(100, 0).videos.find(v => v.id === id);
|
const cachedVideo = videoSyncService.getVideos(100, 0).videos.find(v => v.id === id);
|
||||||
if (cachedVideo) {
|
if (cachedVideo) {
|
||||||
// Apply cached view counts
|
|
||||||
if (this.viewsCache.has(cachedVideo.id)) {
|
|
||||||
cachedVideo.views += this.viewsCache.get(cachedVideo.id)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply face detection data from cache
|
// Apply face detection data from cache
|
||||||
const faceData = this.faceDataCache.get(cachedVideo.id);
|
const faceData = this.faceDataCache.get(cachedVideo.id);
|
||||||
return faceData ? { ...cachedVideo, ...faceData } : cachedVideo;
|
return faceData ? { ...cachedVideo, ...faceData } : cachedVideo;
|
||||||
@ -826,11 +820,6 @@ class BunnyStorage implements IStorage {
|
|||||||
const video = await this.bunnyService.getVideo(id);
|
const video = await this.bunnyService.getVideo(id);
|
||||||
if (!video) return undefined;
|
if (!video) return undefined;
|
||||||
|
|
||||||
// Apply cached view counts
|
|
||||||
if (this.viewsCache.has(video.id)) {
|
|
||||||
video.views += this.viewsCache.get(video.id)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply face detection data from cache
|
// Apply face detection data from cache
|
||||||
const faceData = this.faceDataCache.get(video.id);
|
const faceData = this.faceDataCache.get(video.id);
|
||||||
return faceData ? { ...video, ...faceData } : video;
|
return faceData ? { ...video, ...faceData } : video;
|
||||||
@ -881,10 +870,6 @@ class BunnyStorage implements IStorage {
|
|||||||
this.faceDataCache.set(id, { ...existing, ...faceData });
|
this.faceDataCache.set(id, { ...existing, ...faceData });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update views cache if present
|
|
||||||
if (updates.views !== undefined && typeof updates.views === 'number') {
|
|
||||||
this.viewsCache.set(id, updates.views);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return updated video
|
// Return updated video
|
||||||
return await this.getVideo(id);
|
return await this.getVideo(id);
|
||||||
@ -987,18 +972,9 @@ class BunnyStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateVideoViews(id: string): Promise<void> {
|
async updateVideoViews(id: string): Promise<void> {
|
||||||
try {
|
// Views are tracked automatically by Bunny.net CDN when videos are played
|
||||||
// Persist view count increment to PostgreSQL database
|
// No additional tracking needed - views are fetched fresh every 5 minutes from Bunny.net API
|
||||||
await db.update(videos)
|
console.log(`Video ${id} played - views tracked by Bunny.net CDN`);
|
||||||
.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> {
|
async getVideoCount(search?: string): Promise<number> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user