feat: 移除不必要的 list_memory_scope_keys_updated_since 方法及其测试,优化代码结构

This commit is contained in:
ooodc 2026-05-05 19:53:55 +08:00
parent 7c48a0f7f9
commit 3f5ed6e4e4

View File

@ -779,31 +779,6 @@ impl SessionStore {
Ok(scope_keys) Ok(scope_keys)
} }
pub fn list_memory_scope_keys_updated_since(
&self,
scope_kind: &str,
since_timestamp: i64,
) -> Result<Vec<String>, StorageError> {
let conn = self.conn.lock().expect("session db mutex poisoned");
let mut stmt = conn.prepare(
"
SELECT DISTINCT scope_key
FROM memories
WHERE scope_kind = ?1 AND updated_at > ?2
ORDER BY scope_key ASC
",
)?;
let rows = stmt.query_map(params![scope_kind, since_timestamp], |row| {
row.get::<_, String>(0)
})?;
let mut scope_keys = Vec::new();
for row in rows {
scope_keys.push(row?);
}
Ok(scope_keys)
}
pub fn list_memories_for_scope( pub fn list_memories_for_scope(
&self, &self,
scope_kind: &str, scope_kind: &str,
@ -2368,50 +2343,4 @@ mod tests {
assert_eq!(fetched.completed_at, Some(1_700_000_000_100)); assert_eq!(fetched.completed_at, Some(1_700_000_000_100));
} }
#[test]
fn test_list_memory_scope_keys_updated_since_filters_recent_scopes() {
let store = SessionStore::in_memory().unwrap();
let first = store
.put_memory(&MemoryUpsert {
scope_kind: "user".to_string(),
scope_key: "feishu:user-1".to_string(),
namespace: "profile".to_string(),
memory_key: "work".to_string(),
content: "用户在做AI产品".to_string(),
source_type: "message".to_string(),
source_session_id: None,
source_message_id: None,
source_message_seq: None,
source_channel_name: None,
source_chat_id: None,
})
.unwrap();
let cutoff = first.updated_at;
std::thread::sleep(std::time::Duration::from_millis(2));
store
.put_memory(&MemoryUpsert {
scope_kind: "user".to_string(),
scope_key: "feishu:user-2".to_string(),
namespace: "preferences".to_string(),
memory_key: "style".to_string(),
content: "偏好简洁表达".to_string(),
source_type: "message".to_string(),
source_session_id: None,
source_message_id: None,
source_message_seq: None,
source_channel_name: None,
source_chat_id: None,
})
.unwrap();
let recent_scope_keys = store
.list_memory_scope_keys_updated_since("user", cutoff)
.unwrap();
assert_eq!(recent_scope_keys, vec!["feishu:user-2".to_string()]);
}
} }