mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 00:40:45 +08:00
Paginate chat history so long sessions open quickly.
Load the latest 80 messages first and fetch older pages on scroll-up via before_id, instead of pulling thousands of rows up front. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2a52349668
commit
c3f3992a51
7 changed files with 256 additions and 17 deletions
|
|
@ -89,3 +89,19 @@ def test_sa_chat_message_tool_window_prepend(fresh_sqlite_store: SqliteStore) ->
|
|||
assert len(win) == 2
|
||||
assert win[0].id == asst.id
|
||||
assert win[1].role == "tool"
|
||||
|
||||
|
||||
def test_sa_chat_message_before_id_window(fresh_sqlite_store: SqliteStore) -> None:
|
||||
s = fresh_sqlite_store
|
||||
sess = s.create_session("P")
|
||||
ids = []
|
||||
for i in range(6):
|
||||
ids.append(s.add_message(sess.id, "user", f"m{i}").id)
|
||||
recent = s.get_messages(sess.id, limit=2)
|
||||
assert [m.content for m in recent] == ["m4", "m5"]
|
||||
older = s.get_messages_before_id(session_id=sess.id, before_id=recent[0].id, limit=2)
|
||||
assert [m.content for m in older] == ["m2", "m3"]
|
||||
assert s.exists_message_before_id(session_id=sess.id, before_id=older[0].id) is True
|
||||
head = s.get_messages_before_id(session_id=sess.id, before_id=ids[1], limit=10)
|
||||
assert [m.content for m in head] == ["m0"]
|
||||
assert s.exists_message_before_id(session_id=sess.id, before_id=head[0].id) is False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue