~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
perf: batch domain breakdown queries in get_research_list_with_stats (#3292)
LearningCircuit0a2cd65a1bb5
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.pyindex 7d22cf391c..4b054f2d46 100644--- a/src/local_deep_research/research_library/services/library_service.py+++ b/src/local_deep_research/research_library/services/library_service.py@@ -510,6 +510,35 @@ class LibraryService:)ratings_by_research = {r.research_id: r for r in all_ratings}+ # Batch domain queries to avoid N+1 (same pattern as ratings)+ domain_case = case(+ (+ ResearchResource.url.like("%arxiv.org%"),+ "arxiv.org",+ ),+ (ResearchResource.url.like("%pubmed%"), "pubmed"),+ (+ ResearchResource.url.like("%ncbi.nlm.nih.gov%"),+ "pubmed",+ ),+ else_="other",+ )+ all_domains = (+ session.query(+ ResearchResource.research_id,+ domain_case.label("domain"),+ func.count().label("count"),+ )+ .filter(ResearchResource.research_id.in_(research_ids))+ .group_by(ResearchResource.research_id, domain_case)+ .all()+ if research_ids+ else []+ )+ domains_by_research: Dict[str, list] = {}+ for rid, domain, count in all_domains:+ domains_by_research.setdefault(rid, []).append((domain, count))+research_list = []for (research,@@ -520,29 +549,8 @@ class LibraryService:# Get rating from preloaded dictrating = ratings_by_research.get(research.id)- # Get domain breakdown - simplified version- # Extract domain from URLs using SQL case statements- domains = (- session.query(- case(- (- ResearchResource.url.like("%arxiv.org%"),- "arxiv.org",- ),- (ResearchResource.url.like("%pubmed%"), "pubmed"),- (- ResearchResource.url.like("%ncbi.nlm.nih.gov%"),- "pubmed",- ),- else_="other",- ).label("domain"),- func.count().label("count"),- )- .filter(ResearchResource.research_id == research.id)- .group_by("domain")- .limit(5)- .all()- )+ # Get domain breakdown from preloaded dict+ domains = domains_by_research.get(research.id, [])research_list.append({