diff --git a/app/routes/analyze.tsx b/app/routes/analyze.tsx index 979e3fb..a6d91d3 100644 --- a/app/routes/analyze.tsx +++ b/app/routes/analyze.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState, useEffect, useRef, useCallback } from "react"; import { Link } from "react-router"; import Navbar from "../components/Navbar"; import type { TradingDecision } from "../types/agents"; @@ -211,10 +211,16 @@ export default function Analyze() { }, []); // Auto-load indicators for stocks that don't have them yet (sequential with delay to avoid rate limits) + const loadingRef = useRef(false); + const stocksRef = useRef(stocks); + stocksRef.current = stocks; + useEffect(() => { - const unloaded = stocks.filter((s) => !s.indicatorsLoading && s.indicators.rsi == null); + if (loadingRef.current) return; + const unloaded = stocksRef.current.filter((s) => !s.indicatorsLoading && s.indicators.rsi == null); if (unloaded.length === 0) return; + loadingRef.current = true; let cancelled = false; const loadSequential = async () => { for (const stock of unloaded) { @@ -227,13 +233,14 @@ export default function Analyze() { } else { setStocks((s) => s.map((st) => st.id === stock.id ? { ...st, indicatorsLoading: false } : st)); } - // 500ms delay between each stock to avoid rate limiting await new Promise((r) => setTimeout(r, 500)); } + loadingRef.current = false; }; loadSequential(); return () => { cancelled = true; }; - }, [stocks]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); useEffect(() => { const interval = setInterval(() => { @@ -252,7 +259,8 @@ export default function Analyze() { }, 60000); return () => clearInterval(interval); - }, [stocks]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); const loadIndicators = async (ticker: string) => { try { @@ -348,7 +356,8 @@ export default function Analyze() { }; updatePositions(); - }, [stocks.length]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); const removeStock = async (id: string) => { const stock = stocks.find((s) => s.id === id); diff --git a/prisma/dev.db b/prisma/dev.db index eb13a26..7a27db2 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ