import { cacheGet, cacheSet } from "./cache"; import { getPlanById } from "../db/plans"; /** * Performance optimization utilities */ /** * Get plan with caching */ export async function getPlanWithCache(planId: string) { const cacheKey = `plan:${planId}`; // Try cache first const cached = await cacheGet(cacheKey); if (cached) { return cached; } // Get from database const plan = await getPlanById(planId); // Cache for 5 minutes if (plan) { await cacheSet(cacheKey, plan, 300); } return plan; } /** * Batch API calls */ export async function batchApiCalls( calls: Array<() => Promise>, batchSize = 10 ): Promise { const results: T[] = []; for (let i = 0; i < calls.length; i += batchSize) { const batch = calls.slice(i, i + batchSize); const batchResults = await Promise.all(batch.map((call) => call())); results.push(...batchResults); } return results; }