Просмотр исходного кода

Return version history in newest-first order

Version history pagination now iterates from the end of the deque,
so offset=0 returns the most recent versions first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Void User 5 месяцев назад
Родитель
Сommit
f8de1f52b6
1 измененных файлов с 8 добавлено и 8 удалено
  1. 8 8
      service/src/memory_store.cpp

+ 8 - 8
service/src/memory_store.cpp

@@ -922,14 +922,14 @@ MemoryStore::VersionHistoryResult MemoryStore::getVersionHistory(
         result.documentDeleted = true;
     }
 
-    // Apply pagination
-    uint32_t start = std::min(offset, static_cast<uint32_t>(history.size()));
-    uint32_t end = limit > 0
-        ? std::min(start + limit, static_cast<uint32_t>(history.size()))
-        : static_cast<uint32_t>(history.size());
-
-    for (uint32_t i = start; i < end; ++i) {
-        result.versions.push_back(history[i]);
+    // Apply pagination (newest first: offset=0 returns most recent versions)
+    uint32_t total = static_cast<uint32_t>(history.size());
+    uint32_t skipFromEnd = std::min(offset, total);
+    uint32_t available = total - skipFromEnd;
+    uint32_t count = limit > 0 ? std::min(limit, available) : available;
+
+    for (uint32_t i = 0; i < count; ++i) {
+        result.versions.push_back(history[total - skipFromEnd - 1 - i]);
     }
 
     return result;