Batch deletes

This commit is contained in:
Owen
2025-11-15 11:51:52 -05:00
parent 8ad7bcc0d6
commit de8262d7b9

View File

@@ -93,9 +93,14 @@ export class RateLimitService {
}
}
// Delete old fields in batch
// Delete old fields in batches to avoid call stack size exceeded errors
// The spread operator can cause issues with very large arrays
if (fieldsToDelete.length > 0) {
await client.hdel(key, ...fieldsToDelete);
const batchSize = 1000; // Process 1000 fields at a time
for (let i = 0; i < fieldsToDelete.length; i += batchSize) {
const batch = fieldsToDelete.slice(i, i + batchSize);
await client.hdel(key, ...batch);
}
logger.debug(`Cleaned up ${fieldsToDelete.length} old timestamp fields from ${key}`);
}
} catch (error) {