Address PR review feedback from Gemini Code Assist

Fixes:
- Remove duplicate get_running_analyses function (critical)
- Fix N+1 query in get_pipeline_summary_for_date with batch queries (high)
- Add thread-safety warning comment for running_analyses dict (high)
- Remove package-lock.json from .gitignore and track it (high)
- Config param in memory.py kept for backward compatibility (documented)
This commit is contained in:
hemangjoshi37a 2026-02-01 08:24:35 +11:00
parent d9e71b74cd
commit 86381157d8
4 changed files with 5465 additions and 29 deletions

1
.gitignore vendored
View File

@ -12,7 +12,6 @@ eval_data/
# Node.js
node_modules/
package-lock.json
# Frontend dev artifacts
.frontend-dev/

View File

@ -657,28 +657,40 @@ def get_pipeline_summary_for_date(date: str) -> list:
""", (date,))
symbols = [row['symbol'] for row in cursor.fetchall()]
# Batch fetch all pipeline steps for the date (avoids N+1)
cursor.execute("""
SELECT symbol, step_name, status FROM pipeline_steps
WHERE date = ?
ORDER BY symbol, step_number
""", (date,))
all_steps = cursor.fetchall()
steps_by_symbol = {}
for row in all_steps:
if row['symbol'] not in steps_by_symbol:
steps_by_symbol[row['symbol']] = []
steps_by_symbol[row['symbol']].append({'step_name': row['step_name'], 'status': row['status']})
# Batch fetch agent report counts (avoids N+1)
cursor.execute("""
SELECT symbol, COUNT(*) as count FROM agent_reports
WHERE date = ?
GROUP BY symbol
""", (date,))
agent_counts = {row['symbol']: row['count'] for row in cursor.fetchall()}
# Batch fetch debates existence (avoids N+1)
cursor.execute("""
SELECT DISTINCT symbol FROM debate_history WHERE date = ?
""", (date,))
symbols_with_debates = {row['symbol'] for row in cursor.fetchall()}
summaries = []
for symbol in symbols:
# Get pipeline status
cursor.execute("""
SELECT step_name, status FROM pipeline_steps
WHERE date = ? AND symbol = ?
ORDER BY step_number
""", (date, symbol))
steps = cursor.fetchall()
# Get agent report count
cursor.execute("""
SELECT COUNT(*) as count FROM agent_reports
WHERE date = ? AND symbol = ?
""", (date, symbol))
agent_count = cursor.fetchone()['count']
summaries.append({
'symbol': symbol,
'pipeline_steps': [{'step_name': s['step_name'], 'status': s['status']} for s in steps],
'agent_reports_count': agent_count,
'has_debates': bool(get_debate_history(date, symbol))
'pipeline_steps': steps_by_symbol.get(symbol, []),
'agent_reports_count': agent_counts.get(symbol, 0),
'has_debates': symbol in symbols_with_debates
})
return summaries

View File

@ -15,6 +15,8 @@ PROJECT_ROOT = Path(__file__).parent.parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
# Track running analyses
# NOTE: This is not thread-safe for production multi-worker deployments.
# For production, use Redis or a database-backed job queue instead.
running_analyses = {} # {symbol: {"status": "running", "started_at": datetime, "progress": str}}
app = FastAPI(
@ -585,16 +587,6 @@ async def get_analysis_status(symbol: str):
}
@app.get("/analyze/running")
async def get_running_analyses():
"""Get all currently running analyses."""
running = {k: v for k, v in running_analyses.items() if v.get("status") == "running"}
return {
"running": running,
"count": len(running)
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)

5433
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff