mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 16:10:09 +08:00
Merge pull request #1609 from MohammadHijjawi97/fix/session-search-skip-recycled
fix(sessions): keep recycled chats out of history search
This commit is contained in:
@@ -637,12 +637,15 @@ class PocketBaseSessionStore:
|
||||
def _search() -> dict[str, Any]:
|
||||
pb = _pb()
|
||||
records = pb.collection("sessions").get_full_list(
|
||||
query_params={"filter": _workspace_filter(f"user_id={json.dumps(uid)}")}
|
||||
query_params={
|
||||
"filter": _workspace_filter(f"user_id={json.dumps(uid)} && deleted_at = null")
|
||||
}
|
||||
)
|
||||
records = [
|
||||
record
|
||||
for record in records
|
||||
if _in_workspace(record)
|
||||
and not _to_float(getattr(record, "deleted_at", None))
|
||||
and not str(getattr(record, "session_id", "") or "").startswith("imported_")
|
||||
]
|
||||
records.sort(
|
||||
|
||||
@@ -2750,6 +2750,7 @@ class SQLiteSessionStore:
|
||||
|
||||
match_condition = r"""
|
||||
s.id NOT LIKE 'imported\_%' ESCAPE '\'
|
||||
AND s.deleted_at IS NULL
|
||||
AND (
|
||||
INSTR(LOWER(COALESCE(s.title, '')), LOWER(?)) > 0
|
||||
OR EXISTS (
|
||||
|
||||
@@ -64,3 +64,19 @@ def test_search_ignores_system_only_matches_and_empty_queries(tmp_path) -> None:
|
||||
|
||||
assert run(store.search_sessions("needle")) == {"sessions": [], "total": 0}
|
||||
assert run(store.search_sessions(" ")) == {"sessions": [], "total": 0}
|
||||
|
||||
|
||||
def test_search_skips_sessions_in_the_recycle_bin(tmp_path) -> None:
|
||||
store = SQLiteSessionStore(tmp_path / "history.db")
|
||||
kept = run(store.create_session(title="Bayes notes", session_id="kept"))
|
||||
recycled = run(store.create_session(title="Bayes draft", session_id="recycled"))
|
||||
run(store.add_message(recycled["id"], "user", "Explain Bayes theorem"))
|
||||
run(store.soft_delete_session(recycled["id"]))
|
||||
|
||||
result = run(store.search_sessions("bayes"))
|
||||
|
||||
assert result["total"] == 1
|
||||
assert [row["session_id"] for row in result["sessions"]] == [kept["id"]]
|
||||
|
||||
run(store.restore_session(recycled["id"]))
|
||||
assert run(store.search_sessions("bayes"))["total"] == 2
|
||||
|
||||
@@ -186,6 +186,20 @@ async def test_search_sessions_is_owner_scoped_and_preserves_native_visibility(f
|
||||
assert archived_row["preferences"]["archived"] is True
|
||||
|
||||
|
||||
async def test_search_sessions_skips_sessions_in_the_recycle_bin(fake_pb) -> None:
|
||||
store = PocketBaseSessionStore()
|
||||
with as_user("alice"):
|
||||
kept = await store.create_session(title="Bayes notes", session_id="s_kept")
|
||||
recycled = await store.create_session(title="Bayes draft", session_id="s_recycled")
|
||||
await store.add_message(recycled["id"], "user", "Explain Bayes theorem")
|
||||
await store.soft_delete_session(recycled["id"])
|
||||
|
||||
result = await store.search_sessions("bayes")
|
||||
|
||||
assert result["total"] == 1
|
||||
assert [row["session_id"] for row in result["sessions"]] == [kept["id"]]
|
||||
|
||||
|
||||
async def test_legacy_workspace_preferences_are_normalized_at_repository_boundary(
|
||||
fake_pb,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user