Improve platform speed and search responsiveness

Implement performance optimizations including HTTP compression, enhanced caching strategies, reduced search debounce time, and optimized thumbnail generation.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: d7424866-83d1-4486-a212-ac12b4c7becf
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/d7424866-83d1-4486-a212-ac12b4c7becf/UCWygK2
This commit is contained in:
sebastjanartic
2025-08-28 15:04:47 +00:00
parent 177f5d945f
commit e40b738478
8 changed files with 127 additions and 26 deletions
+31 -8
View File
@@ -1,6 +1,7 @@
import type { Express, Request, Response } from "express";
import { createServer, type Server } from "http";
import express from "express";
import compression from "compression";
import { storage } from "./storage";
import { z } from "zod";
import {
@@ -52,6 +53,19 @@ const authenticate = (req: Request, res: Response, next: any) => {
};
export async function registerRoutes(app: Express): Promise<Server> {
// Add compression middleware for better performance
app.use(compression({
level: 6,
threshold: 1024, // Only compress responses larger than 1KB
filter: (req, res) => {
// Don't compress video files
if (req.headers['accept']?.includes('video/')) {
return false;
}
return compression.filter(req, res);
}
}));
// Configure session middleware
app.use(session({
secret: process.env.SESSION_SECRET || 'dev-secret-key',
@@ -164,14 +178,6 @@ export async function registerRoutes(app: Express): Promise<Server> {
app.get("/api/videos", async (req, res) => {
try {
// Set cache headers for better performance
res.set({
'Cache-Control': 'public, max-age=300, s-maxage=300', // 5 minutes cache
'ETag': `"videos-${Date.now()}"`,
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY'
});
const limit = parseInt(req.query.limit as string) || 20;
const offset = parseInt(req.query.offset as string) || 0;
const search = req.query.search as string;
@@ -179,6 +185,23 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Skip search for queries shorter than 2 characters for performance
const searchQuery = search && search.length >= 2 ? search : undefined;
// Create cache key for ETag
const cacheKey = `videos-${limit}-${offset}-${searchQuery || 'all'}`;
const etag = `"${cacheKey}"`;
// Check if client has cached version
if (req.headers['if-none-match'] === etag) {
return res.status(304).end();
}
// Set optimized cache headers
res.set({
'Cache-Control': 'public, max-age=120, stale-while-revalidate=300', // 2 min cache, 5 min stale
'ETag': etag,
'X-Content-Type-Options': 'nosniff',
'Vary': 'Accept-Encoding'
});
console.log(`Fetching videos: limit=${limit}, offset=${offset}, search=${searchQuery}`);
const videos = await storage.getVideos(limit, offset, searchQuery);