From 9fda0058ea7f6026b8720b0544c4edf92d9b8832 Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Tue, 21 Oct 2025 12:13:28 -0500 Subject: [PATCH] Refactor Redis command execution in hooks.server.ts to use the send method for improved performance. Remove unused clearAllCache function from api.ts to clean up the codebase. --- src/hooks.server.ts | 5 +---- src/lib/api.ts | 6 +----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index e003634..15b0359 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -59,10 +59,7 @@ async function consumeSlidingWindow(key: string, points: number, windowSeconds: redis.call('EXPIRE', key, windowStart + (60*60*24) == 0 and 60 or math.floor((now - windowStart)/1000) + 5) return count `; - const count = (await client.eval(lua, { - keys: [listKey], - arguments: [String(now), String(windowStart), String(points), String(MAX_REQUESTS)] - })) as number; + const count = await client.send(lua, [listKey, String(now), String(windowStart), String(points), String(MAX_REQUESTS)]); return { allowed: count <= MAX_REQUESTS, remaining: Math.max(0, MAX_REQUESTS - count) }; } diff --git a/src/lib/api.ts b/src/lib/api.ts index b033402..c6f153f 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -452,8 +452,4 @@ export async function invalidateSearchCache() { // This would need to be implemented with pattern matching // For now, we'll just clear the package count cache await cache.del(CacheManager.getPackageCountKey()); -} - -export async function clearAllCache() { - await cache.flush(); -} \ No newline at end of file +} \ No newline at end of file