MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / checkProposeRateLimit

Function checkProposeRateLimit

server/src/routes/content.ts:53–74  ·  view source on GitHub ↗
(userId: string)

Source from the content-addressed store, hash-verified

51const proposeHistory = new Map<string, number[]>();
52
53function checkProposeRateLimit(userId: string): { ok: true } | { ok: false; retryAfterMs: number } {
54 if (userId.startsWith('system:')) return { ok: true };
55 const now = Date.now();
56 const cutoff = now - PROPOSE_WINDOW_MS;
57 const history = (proposeHistory.get(userId) ?? []).filter(t => t > cutoff);
58 if (history.length >= PROPOSE_MAX_PER_WINDOW) {
59 return { ok: false, retryAfterMs: history[0] + PROPOSE_WINDOW_MS - now };
60 }
61 history.push(now);
62 proposeHistory.set(userId, history);
63 // Opportunistic GC — if we've accumulated entries for many users,
64 // prune ones with no recent activity. Cheap: runs once per call when
65 // the map is large.
66 if (proposeHistory.size > 1000) {
67 for (const [key, entries] of proposeHistory) {
68 const recent = entries.filter(t => t > cutoff);
69 if (recent.length === 0) proposeHistory.delete(key);
70 else proposeHistory.set(key, recent);
71 }
72 }
73 return { ok: true };
74}
75
76interface ContentAuthor {
77 user_id: string;

Callers 1

proposeContentForUserFunction · 0.85

Calls 4

nowMethod · 0.80
deleteMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected