mirror of
https://github.com/LukeHagar/pypistats.dev.git
synced 2025-12-06 04:21:09 +00:00
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.
This commit is contained in:
@@ -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)
|
redis.call('EXPIRE', key, windowStart + (60*60*24) == 0 and 60 or math.floor((now - windowStart)/1000) + 5)
|
||||||
return count
|
return count
|
||||||
`;
|
`;
|
||||||
const count = (await client.eval(lua, {
|
const count = await client.send(lua, [listKey, String(now), String(windowStart), String(points), String(MAX_REQUESTS)]);
|
||||||
keys: [listKey],
|
|
||||||
arguments: [String(now), String(windowStart), String(points), String(MAX_REQUESTS)]
|
|
||||||
})) as number;
|
|
||||||
return { allowed: count <= MAX_REQUESTS, remaining: Math.max(0, MAX_REQUESTS - count) };
|
return { allowed: count <= MAX_REQUESTS, remaining: Math.max(0, MAX_REQUESTS - count) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -452,8 +452,4 @@ export async function invalidateSearchCache() {
|
|||||||
// This would need to be implemented with pattern matching
|
// This would need to be implemented with pattern matching
|
||||||
// For now, we'll just clear the package count cache
|
// For now, we'll just clear the package count cache
|
||||||
await cache.del(CacheManager.getPackageCountKey());
|
await cache.del(CacheManager.getPackageCountKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function clearAllCache() {
|
|
||||||
await cache.flush();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user