periderm-cli 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/scanner/checks.js +71 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
package/dist/scanner/checks.js
CHANGED
|
@@ -622,6 +622,76 @@ const deadEndPage = (source, file) => {
|
|
|
622
622
|
return out;
|
|
623
623
|
};
|
|
624
624
|
// ───────────────────────────────────────────────────────────────────────
|
|
625
|
+
// 14. Aggressive DB/API polling for "live" updates instead of websockets
|
|
626
|
+
// ───────────────────────────────────────────────────────────────────────
|
|
627
|
+
const dbPollingAbuse = (source, file) => {
|
|
628
|
+
const out = [];
|
|
629
|
+
if (!/\.(tsx|jsx|ts|js)$/.test(file))
|
|
630
|
+
return out;
|
|
631
|
+
const intervalPatterns = [
|
|
632
|
+
[/refetchInterval\s*:\s*(\d+)/g, "TanStack/React Query refetchInterval"],
|
|
633
|
+
[/refreshInterval\s*:\s*(\d+)/g, "SWR refreshInterval"],
|
|
634
|
+
[/(?:pollInterval|pollingInterval)\s*[:=]\s*(\d+)/g, "polling interval"],
|
|
635
|
+
];
|
|
636
|
+
for (const [re, label] of intervalPatterns) {
|
|
637
|
+
let m;
|
|
638
|
+
while ((m = re.exec(source))) {
|
|
639
|
+
const ms = parseInt(m[1], 10);
|
|
640
|
+
if (ms > 0 && ms < 5000) {
|
|
641
|
+
out.push(mkFinding({
|
|
642
|
+
id: "db-polling-interval",
|
|
643
|
+
category: "Runaway Cloud Costs",
|
|
644
|
+
severity: "critical",
|
|
645
|
+
file,
|
|
646
|
+
line: lineOf(source, m.index),
|
|
647
|
+
message: `${label} set to ${ms}ms — polling the database/API several times per second.`,
|
|
648
|
+
why: "Vibecoded \"live feedback\" loops hammer your DB/API on every tab open. On Supabase/Firebase/serverless this can burn through free tiers and bankrupt you overnight. Use websockets, Supabase Realtime, or SSE instead.",
|
|
649
|
+
fix: "Replace polling with Supabase Realtime (.channel/.subscribe), WebSockets, or server-sent events. If you must poll, use ≥30s intervals and pause when the tab is hidden.",
|
|
650
|
+
aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, ${label} is ${ms}ms — far too aggressive for live updates. Refactor to Supabase Realtime channels or WebSockets for push updates, or raise the interval to 30s+ with visibility-based pausing.`,
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const intervalFetchRe = /setInterval\s*\(\s*(?:async\s*)?\(?[^)]*\)?\s*=>\s*\{[\s\S]{0,700}?(supabase\.(?:from|rpc)|\.select\s*\(|fetch\s*\(|axios\.|\.get\s*\()/gi;
|
|
656
|
+
let m;
|
|
657
|
+
while ((m = intervalFetchRe.exec(source))) {
|
|
658
|
+
const snippet = m[0];
|
|
659
|
+
const hasRealtime = /\.channel\s*\(|\.subscribe\s*\(|WebSocket|useRealtime|postgres_changes/.test(source);
|
|
660
|
+
const intervalMs = snippet.match(/setInterval\s*\([^,]+,\s*(\d+)/)?.[1];
|
|
661
|
+
const ms = intervalMs ? parseInt(intervalMs, 10) : 1000;
|
|
662
|
+
if (ms < 5000 && !hasRealtime) {
|
|
663
|
+
out.push(mkFinding({
|
|
664
|
+
id: "setinterval-db-poll",
|
|
665
|
+
category: "Runaway Cloud Costs",
|
|
666
|
+
severity: "critical",
|
|
667
|
+
file,
|
|
668
|
+
line: lineOf(source, m.index),
|
|
669
|
+
message: `setInterval (${ms}ms) repeatedly hits the database/API for live updates.`,
|
|
670
|
+
why: "This pattern mimics realtime with expensive polling. Every user multiplies reads/writes. It is the #1 surprise bill for AI-generated dashboards and chat UIs.",
|
|
671
|
+
fix: "Use Supabase Realtime, WebSockets, or SSE. Delete the interval and subscribe to push events instead.",
|
|
672
|
+
aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, a setInterval every ${ms}ms fetches from the database/API. Replace with Supabase Realtime (.channel().on('postgres_changes')) or WebSockets so updates push instead of poll.`,
|
|
673
|
+
}));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const useEffectPollRe = /useEffect\s*\(\s*\(\s*\)\s*=>\s*\{[\s\S]{0,500}?setInterval\s*\([\s\S]{0,400}?(supabase\.(?:from|rpc)|fetch\s*\()/g;
|
|
677
|
+
while ((m = useEffectPollRe.exec(source))) {
|
|
678
|
+
if (/\.channel\s*\(|WebSocket|realtime/.test(m[0]))
|
|
679
|
+
continue;
|
|
680
|
+
out.push(mkFinding({
|
|
681
|
+
id: "useeffect-polling",
|
|
682
|
+
category: "Runaway Cloud Costs",
|
|
683
|
+
severity: "high",
|
|
684
|
+
file,
|
|
685
|
+
line: lineOf(source, m.index),
|
|
686
|
+
message: "useEffect sets up interval polling against the database/API.",
|
|
687
|
+
why: "Polling in useEffect is a common vibecoder pattern for \"live\" dashboards. It scales linearly with users and tabs, unlike websocket subscriptions.",
|
|
688
|
+
fix: "Switch to Supabase Realtime subscriptions or WebSockets. Add cleanup if you keep any polling.",
|
|
689
|
+
aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, useEffect starts interval polling for data. Replace with a Realtime subscription (supabase.channel) or WebSocket listener, and return an unsubscribe cleanup.`,
|
|
690
|
+
}));
|
|
691
|
+
}
|
|
692
|
+
return out;
|
|
693
|
+
};
|
|
694
|
+
// ───────────────────────────────────────────────────────────────────────
|
|
625
695
|
// Registry
|
|
626
696
|
// ───────────────────────────────────────────────────────────────────────
|
|
627
697
|
const CHECKS = [
|
|
@@ -646,6 +716,7 @@ const CHECKS = [
|
|
|
646
716
|
missingRateLimit,
|
|
647
717
|
idorDataFetch,
|
|
648
718
|
deadEndPage,
|
|
719
|
+
dbPollingAbuse,
|
|
649
720
|
];
|
|
650
721
|
export const PER_FILE_CHECK_COUNT = CHECKS.length;
|
|
651
722
|
export function runChecks(source, file, ast) {
|