From d6b22e8fede59e4c5d576a673f9b744cfbdc9271 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 24 Jul 2026 03:27:48 +0800 Subject: [PATCH] fix: list_documents tie-breaker rowid ASC, matching the cloud's effect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 11ba63d copied the server's "id" ASC rule, but server ids are time-ordered cuids so that rule means insertion order there — local uuid4 doc_ids sort randomly. rowid ASC reproduces the actual effect. --- pageindex/storage/sqlite.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pageindex/storage/sqlite.py b/pageindex/storage/sqlite.py index c253ef3..22ca65e 100644 --- a/pageindex/storage/sqlite.py +++ b/pageindex/storage/sqlite.py @@ -265,7 +265,10 @@ class SQLiteStorage: def list_documents(self, collection: str) -> list[dict]: conn = self._get_conn() rows = conn.execute( - "SELECT doc_id, doc_name, doc_description, doc_type FROM documents WHERE collection_name = ? ORDER BY created_at DESC, doc_id ASC", + # Tie-breaker mirrors the cloud's effective order: server ids are + # time-ordered cuids, so "id" ASC there means insertion order — + # which locally is rowid ASC (uuid4 doc_ids sort randomly). + "SELECT doc_id, doc_name, doc_description, doc_type FROM documents WHERE collection_name = ? ORDER BY created_at DESC, rowid ASC", (collection,), ).fetchall() return [{"doc_id": r[0], "doc_name": r[1], "doc_description": r[2] or "", "doc_type": r[3]} for r in rows]