refactor(memory): simplify read_unprocessed_history cursor guard

Replace verbose loop with one-liner list comprehension using
e.get("cursor", 0) to handle missing cursor keys.
This commit is contained in:
chengyongru
2026-04-16 12:32:38 +08:00
committed by Xubin Ren
parent f4a7ad16aa
commit 524c097f76
+1 -9
View File
@@ -245,15 +245,7 @@ class MemoryStore:
def read_unprocessed_history(self, since_cursor: int) -> list[dict[str, Any]]:
"""Return history entries with cursor > *since_cursor*."""
entries = []
for e in self._read_entries():
cursor = e.get("cursor")
if cursor is None:
logger.warning("Skipping history entry without cursor: {}", e.get("timestamp", "unknown"))
continue
if cursor > since_cursor:
entries.append(e)
return entries
return [e for e in self._read_entries() if e.get("cursor", 0) > since_cursor]
def compact_history(self) -> None:
"""Drop oldest entries if the file exceeds *max_history_entries*."""