fix: sorting of conv lists, streaming responses

This commit is contained in:
Per Stark
2025-04-16 16:23:08 +02:00
parent 6950009675
commit 0185607384
5 changed files with 132 additions and 165 deletions

View File

@@ -423,7 +423,7 @@ impl User {
.client
.query(
"SELECT * FROM type::table($table_name) WHERE user_id = $user_id
ORDER BY updated_at DESC",
ORDER BY created_at DESC",
)
.bind(("table_name", Conversation::table_name()))
.bind(("user_id", user_id.to_string()))
@@ -789,7 +789,7 @@ mod tests {
for i in 0..5 {
let mut conv = Conversation::new(user_id.to_string(), format!("Conv {}", i));
// Fake updated_at i minutes apart
conv.updated_at = chrono::Utc::now() - chrono::Duration::minutes(i);
conv.created_at = chrono::Utc::now() - chrono::Duration::minutes(i);
db.store_item(conv.clone())
.await
.expect("Failed to store conversation");
@@ -806,13 +806,13 @@ mod tests {
for window in retrieved.windows(2) {
// Assert each earlier conversation has updated_at >= later conversation
assert!(
window[0].updated_at >= window[1].updated_at,
"Conversations not ordered descending by updated_at"
window[0].created_at >= window[1].created_at,
"Conversations not ordered descending by created_at"
);
}
// (Optional) Check first conversation title matches the most recently updated
let most_recent = conversations.iter().max_by_key(|c| c.updated_at).unwrap();
// Check first conversation title matches the most recently updated
let most_recent = conversations.iter().max_by_key(|c| c.created_at).unwrap();
assert_eq!(retrieved[0].id, most_recent.id);
}
}