Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: scope RateLimitEstimate preload to relevant engine types (#2092)

LearningCircuitddc675a102f2
diff --git a/src/local_deep_research/web/routes/metrics_routes.py b/src/local_deep_research/web/routes/metrics_routes.py
index 22ac9c55e2..a77d7d3806 100644
--- a/src/local_deep_research/web/routes/metrics_routes.py
+++ b/src/local_deep_research/web/routes/metrics_routes.py
@@ -708,9 +708,15 @@ def get_rate_limiting_analytics(period="30d", username=None):
)
engine_types = [row.engine_type for row in engine_types_query.all()]
- # Preload all estimates to avoid N+1 queries
- all_estimates = session.query(RateLimitEstimate).all()
- estimates_by_engine = {e.engine_type: e for e in all_estimates}
+ # Preload estimates for relevant engines to avoid N+1 queries
+ estimates_by_engine = {}
+ if engine_types:
+ all_estimates = (
+ session.query(RateLimitEstimate)
+ .filter(RateLimitEstimate.engine_type.in_(engine_types))
+ .all()
+ )
+ estimates_by_engine = {e.engine_type: e for e in all_estimates}
for engine_type in engine_types:
engine_attempts_list = [