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(library): bound research-list dropdown query (#4560) (#4719)

LearningCircuit9c2cbd0c9714
diff --git a/changelog.d/+bound-research-dropdown.bugfix.md b/changelog.d/+bound-research-dropdown.bugfix.md
new file mode 100644
index 0000000000..0dab32b36d
--- /dev/null
+++ b/changelog.d/+bound-research-dropdown.bugfix.md
@@ -0,0 +1 @@
+The research-session filter dropdown on the library page no longer loads every research row unbounded; it is now capped to the most-recent sessions, avoiding excessive memory/DOM use on very large histories (#4560).
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index a8fc189cd6..6a712059f3 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -36,6 +36,14 @@ from ..utils import (
open_file_location,
)
+# Filter dropdowns (library page + ``/api/research-list``) load research
+# sessions into a client-side ``<select>``. Bound the query so a very large
+# history cannot pull every row into memory / the DOM on each page load
+# (#4560). The query already projects to three small columns, so this is a
+# safety cap rather than a crash fix; realistic histories are far smaller, and
+# comprehensive large-scale filtering is a server-side-search follow-up.
+_DROPDOWN_RESEARCH_LIMIT = 1000
+
class LibraryService:
"""Service for managing and querying the document library."""
@@ -556,7 +564,9 @@ class LibraryService:
def get_research_list_for_dropdown(self) -> List[Dict]:
"""Get minimal research session info for filter dropdowns.
- Returns only id, title, and query — no joins or aggregates.
+ Returns only id, title, and query — no joins or aggregates — for at
+ most the ``_DROPDOWN_RESEARCH_LIMIT`` most-recent sessions, so a very
+ large history cannot load every row into memory / the DOM (#4560).
"""
with get_user_db_session(self.username) as session:
results = (
@@ -566,6 +576,7 @@ class LibraryService:
ResearchHistory.query,
)
.order_by(ResearchHistory.created_at.desc())
+ .limit(_DROPDOWN_RESEARCH_LIMIT)
.all()
)
return [
diff --git a/tests/research_library/services/test_library_service_collections_stats.py b/tests/research_library/services/test_library_service_collections_stats.py
index 9a3f29d5d5..25aa3c21d9 100644
--- a/tests/research_library/services/test_library_service_collections_stats.py
+++ b/tests/research_library/services/test_library_service_collections_stats.py
@@ -227,6 +227,7 @@ class TestGetResearchListForDropdown:
mock_query = MagicMock()
mock_query.order_by.return_value = mock_query
+ mock_query.limit.return_value = mock_query
mock_query.all.return_value = [mock_row1, mock_row2]
mock_session.query.return_value = mock_query
_mock_session_cm(mocker, mock_session)
@@ -254,6 +255,7 @@ class TestGetResearchListForDropdown:
mock_query = MagicMock()
mock_query.order_by.return_value = mock_query
+ mock_query.limit.return_value = mock_query
mock_query.all.return_value = []
mock_session.query.return_value = mock_query
_mock_session_cm(mocker, mock_session)
@@ -262,6 +264,28 @@ class TestGetResearchListForDropdown:
assert result == []
+ def test_query_is_bounded_by_dropdown_limit(self, mocker):
+ """The dropdown query applies the safety cap so a very large history
+ cannot be loaded unbounded (#4560). Fails if ``.limit()`` is dropped."""
+ from local_deep_research.research_library.services.library_service import (
+ _DROPDOWN_RESEARCH_LIMIT,
+ )
+
+ service = _make_service()
+ mock_session = MagicMock()
+ mock_query = MagicMock()
+ mock_query.order_by.return_value = mock_query
+ mock_query.limit.return_value = mock_query
+ mock_query.all.return_value = []
+ mock_session.query.return_value = mock_query
+ _mock_session_cm(mocker, mock_session)
+
+ service.get_research_list_for_dropdown()
+
+ mock_query.limit.assert_called_once_with(_DROPDOWN_RESEARCH_LIMIT)
+ # Cap is applied after ordering by recency, not before.
+ mock_query.order_by.assert_called_once()
+
# ============== get_research_list_with_stats ==============