MCPcopy Create free account
hub / github.com/avoidwork/tenso / checkWithReset

Function checkWithReset

benchmarks/rate-limiting.js:216–240  ·  view source on GitHub ↗
(req, needsReset = false)

Source from the content-addressed store, hash-verified

214 const rateStore = new Map();
215
216 const checkWithReset = (req, needsReset = false) => {
217 const reqId = req.sessionID || req.ip;
218 const currentTime = Math.floor(Date.now() / 1000);
219
220 if (!rateStore.has(reqId)) {
221 rateStore.set(reqId, {
222 remaining: 99,
223 reset: currentTime + (needsReset ? 0 : 900) // Force reset if needed
224 });
225 }
226
227 const state = rateStore.get(reqId);
228
229 if (needsReset || currentTime >= state.reset) {
230 // Simulate window reset
231 state.remaining = 100;
232 state.reset = currentTime + 900;
233
234 return { reset: true, remaining: state.remaining };
235 }
236
237 state.remaining--;
238
239 return { reset: false, remaining: state.remaining };
240 };
241
242 suite
243 .add("Rate Limit - Normal check (no reset)", () => {

Callers 1

benchmarkWindowResetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected