From dc193a061ad855cdb149c581f8439b2aa98ee6db Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Tue, 12 May 2026 16:06:32 +0800 Subject: [PATCH] fix(api): replace async block in Option::and_then with match for proper await --- libs/api/chat/stream.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/libs/api/chat/stream.rs b/libs/api/chat/stream.rs index f315537..4b47825 100644 --- a/libs/api/chat/stream.rs +++ b/libs/api/chat/stream.rs @@ -336,29 +336,28 @@ pub fn create_chat_sse_stream( } // Record billing after successful AI response - let billing_version_id = model::Entity::find() + let billing_version_id = match model::Entity::find() .filter(model::Column::Name.eq(&model_name)) .one(service.db.reader()) .await .ok() .flatten() - .and_then(|m| { - // Resolve to active/default version for pricing lookup + { + Some(m) => { let reader = service.db.reader(); - async move { - model_version::Entity::find() - .filter(model_version::Column::ModelId.eq(m.id)) - .filter(model_version::Column::Status.eq("active")) - .order_by_desc(model_version::Column::IsDefault) - .order_by_desc(model_version::Column::ReleaseDate) - .one(reader) - .await - .ok() - .flatten() - .map(|v| v.id) - } - }) - .await; + model_version::Entity::find() + .filter(model_version::Column::ModelId.eq(m.id)) + .filter(model_version::Column::Status.eq("active")) + .order_by_desc(model_version::Column::IsDefault) + .order_by_desc(model_version::Column::ReleaseDate) + .one(reader) + .await + .ok() + .flatten() + .map(|v| v.id) + } + None => None, + }; if let Some(version_id) = billing_version_id { match agent::billing::record_ai_usage(