fix: сохранить микросекунды в created_at для корректной keyset-пагинации

Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat>
This commit is contained in:
Evgeny Bushkov
2026-10-23 18:38:19 +03:00
co-authored by aider
parent eebecc74ff
commit ed7b43ecac
2 changed files with 4 additions and 14 deletions
+2 -9
View File
@@ -161,7 +161,6 @@ def create_chat(
if store.get_user(mid) is None:
raise ApiError(400, "invalid_request", "Неизвестный участник чата")
chat = store.create_chat(title, member_ids)
chat.pop("_cursor_created_at", None)
return JSONResponse(chat, status_code=201)
@@ -180,9 +179,7 @@ def list_chats(
next_cursor = None
if has_more and items:
last = items[-1]
next_cursor = encode_cursor(last["_cursor_created_at"], last["id"], scope)
for item in items:
item.pop("_cursor_created_at", None)
next_cursor = encode_cursor(last["created_at"], last["id"], scope)
return {"items": items, "next_cursor": next_cursor}
@@ -200,7 +197,6 @@ def get_chat(
chat = store.get_chat(chat_id)
if chat is None:
raise ApiError(404, "not_found", "Чат не найден")
chat.pop("_cursor_created_at", None)
return chat
@@ -218,7 +214,6 @@ def create_message(
raise ApiError(404, "not_found", "Чат не найден")
text = validate_create_message(body)
message = store.add_message(chat_id, caller, text)
message.pop("_cursor_created_at", None)
return JSONResponse(message, status_code=201)
@@ -242,7 +237,5 @@ def list_messages(
next_cursor = None
if has_more and items:
last = items[-1]
next_cursor = encode_cursor(last["_cursor_created_at"], last["id"], scope)
for item in items:
item.pop("_cursor_created_at", None)
next_cursor = encode_cursor(last["created_at"], last["id"], scope)
return {"items": items, "next_cursor": next_cursor}
+2 -5
View File
@@ -17,7 +17,8 @@ def new_id() -> str:
def _iso(dt: datetime) -> str:
return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
"""RFC 3339 UTC с суффиксом Z, микросекунды сохраняются для keyset-пагинации."""
return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
def _user_row(row: tuple) -> dict[str, Any]:
@@ -37,8 +38,6 @@ def _chat_row(row: tuple, member_ids: list[str]) -> dict[str, Any]:
"title": title,
"member_ids": member_ids,
"created_at": _iso(created_at),
# Полное значение для keyset-cursor; handler вырезает перед отдачей.
"_cursor_created_at": created_at.isoformat(),
}
@@ -50,8 +49,6 @@ def _message_row(row: tuple) -> dict[str, Any]:
"sender_id": str(sender_id),
"text": text,
"created_at": _iso(created_at),
# Полное значение для keyset-cursor; handler вырезает перед отдачей.
"_cursor_created_at": created_at.isoformat(),
}