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

Function checkRateLimitWithConfig

benchmarks/rate-limiting.js:164–187  ·  view source on GitHub ↗
(req, config, store)

Source from the content-addressed store, hash-verified

162 const rateStores = configs.map(() => new Map());
163
164 const checkRateLimitWithConfig = (req, config, store) => {
165 const reqId = req.sessionID || req.ip;
166 const currentTime = Math.floor(Date.now() / 1000);
167
168 if (!store.has(reqId)) {
169 store.set(reqId, {
170 remaining: config.limit - 1,
171 reset: currentTime + config.reset
172 });
173
174 return true;
175 }
176
177 const state = store.get(reqId);
178
179 if (currentTime >= state.reset) {
180 state.remaining = config.limit - 1;
181 state.reset = currentTime + config.reset;
182
183 return true;
184 }
185
186 return state.remaining > 0 ? (state.remaining--, true) : false;
187 };
188
189 configs.forEach((config, index) => {
190 suite.add(`Rate Limit - ${config.name}`, () => {

Callers 1

benchmarkDifferentLimitsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected