diff --git a/utils/database.py b/utils/database.py index 42b237c..fb64fb5 100644 --- a/utils/database.py +++ b/utils/database.py @@ -548,7 +548,7 @@ class Database: finally: conn.close() - async def get_recent_memories(self, user_id: int, limit: int = 10) -> list[dict]: + async def get_recent_memories(self, user_id: int, limit: int = 5) -> list[dict]: """Get the N most recent non-expired memories for a user.""" if not self._available: return [] @@ -583,7 +583,7 @@ class Database: finally: conn.close() - async def get_memories_by_topics(self, user_id: int, topic_keywords: list[str], limit: int = 10) -> list[dict]: + async def get_memories_by_topics(self, user_id: int, topic_keywords: list[str], limit: int = 5) -> list[dict]: """Get non-expired memories matching any of the given topic keywords via LIKE.""" if not self._available: return [] @@ -655,18 +655,18 @@ class Database: finally: conn.close() - async def prune_excess_memories(self, user_id: int, cap: int = 50) -> int: + async def prune_excess_memories(self, user_id: int, max_memories: int = 50) -> int: """Delete excess memories for a user beyond the cap, keeping high importance and newest first. Returns count deleted.""" if not self._available: return 0 try: - return await asyncio.to_thread(self._prune_excess_memories_sync, user_id, cap) + return await asyncio.to_thread(self._prune_excess_memories_sync, user_id, max_memories) except Exception: logger.exception("Failed to prune excess memories") return 0 - def _prune_excess_memories_sync(self, user_id, cap) -> int: + def _prune_excess_memories_sync(self, user_id, max_memories) -> int: conn = self._connect() try: cursor = conn.cursor() @@ -689,7 +689,7 @@ class Database: ) ranked WHERE rn > ? )""", - user_id, cap, + user_id, max_memories, ) count = cursor.rowcount cursor.close()