style: 对存储模块应用 rustfmt 格式化
This commit is contained in:
parent
d3ee430aa9
commit
e3e32c725d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1635,7 +1635,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "picobot"
|
name = "picobot"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
@ -53,7 +53,10 @@ pub(super) fn ensure_messages_schema(conn: &Connection) -> Result<(), StorageErr
|
|||||||
|
|
||||||
// Token usage 字段(仅 assistant 消息有值,来自 LLM 响应)
|
// Token usage 字段(仅 assistant 消息有值,来自 LLM 响应)
|
||||||
if !has_column(conn, "messages", "prompt_tokens")? {
|
if !has_column(conn, "messages", "prompt_tokens")? {
|
||||||
add_column_if_missing(conn, "ALTER TABLE messages ADD COLUMN prompt_tokens INTEGER")?;
|
add_column_if_missing(
|
||||||
|
conn,
|
||||||
|
"ALTER TABLE messages ADD COLUMN prompt_tokens INTEGER",
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
if !has_column(conn, "messages", "completion_tokens")? {
|
if !has_column(conn, "messages", "completion_tokens")? {
|
||||||
add_column_if_missing(
|
add_column_if_missing(
|
||||||
@ -147,8 +150,7 @@ pub(super) fn ensure_memory_scope_key_migration(conn: &Connection) -> Result<(),
|
|||||||
// 版本 0:未迁移;版本 1:memory_scope_key 迁移已完成。
|
// 版本 0:未迁移;版本 1:memory_scope_key 迁移已完成。
|
||||||
const MEMORY_SCOPE_KEY_MIGRATION_VERSION: i64 = 1;
|
const MEMORY_SCOPE_KEY_MIGRATION_VERSION: i64 = 1;
|
||||||
|
|
||||||
let current_version: i64 =
|
let current_version: i64 = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?;
|
||||||
conn.query_row("PRAGMA user_version", [], |row| row.get(0))?;
|
|
||||||
|
|
||||||
if current_version >= MEMORY_SCOPE_KEY_MIGRATION_VERSION {
|
if current_version >= MEMORY_SCOPE_KEY_MIGRATION_VERSION {
|
||||||
// 已迁移过,跳过
|
// 已迁移过,跳过
|
||||||
@ -182,7 +184,10 @@ pub(super) fn ensure_memory_scope_key_migration(conn: &Connection) -> Result<(),
|
|||||||
|
|
||||||
// 步骤3:记录迁移版本,后续启动直接跳过
|
// 步骤3:记录迁移版本,后续启动直接跳过
|
||||||
conn.execute(
|
conn.execute(
|
||||||
&format!("PRAGMA user_version = {}", MEMORY_SCOPE_KEY_MIGRATION_VERSION),
|
&format!(
|
||||||
|
"PRAGMA user_version = {}",
|
||||||
|
MEMORY_SCOPE_KEY_MIGRATION_VERSION
|
||||||
|
),
|
||||||
[],
|
[],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@ -27,11 +27,7 @@ pub(super) fn map_usage_row(
|
|||||||
let completion: Option<i64> = row.get(completion_idx)?;
|
let completion: Option<i64> = row.get(completion_idx)?;
|
||||||
let total: Option<i64> = row.get(total_idx)?;
|
let total: Option<i64> = row.get(total_idx)?;
|
||||||
let context_window: Option<i64> = row.get(context_window_idx)?;
|
let context_window: Option<i64> = row.get(context_window_idx)?;
|
||||||
if prompt.is_none()
|
if prompt.is_none() && completion.is_none() && total.is_none() && context_window.is_none() {
|
||||||
&& completion.is_none()
|
|
||||||
&& total.is_none()
|
|
||||||
&& context_window.is_none()
|
|
||||||
{
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(MessageUsage {
|
Ok(Some(MessageUsage {
|
||||||
|
|||||||
@ -692,9 +692,7 @@ fn test_scheduler_job_roundtrip_and_runtime_update() {
|
|||||||
fn test_get_topic_message_count_uses_count_query() {
|
fn test_get_topic_message_count_uses_count_query() {
|
||||||
let store = SessionStore::in_memory().unwrap();
|
let store = SessionStore::in_memory().unwrap();
|
||||||
let session = store.create_cli_session(Some("topic-count")).unwrap();
|
let session = store.create_cli_session(Some("topic-count")).unwrap();
|
||||||
let topic = store
|
let topic = store.create_topic(&session.id, "topic-1", None).unwrap();
|
||||||
.create_topic(&session.id, "topic-1", None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// 初始计数为 0
|
// 初始计数为 0
|
||||||
assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 0);
|
assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 0);
|
||||||
@ -702,11 +700,7 @@ fn test_get_topic_message_count_uses_count_query() {
|
|||||||
// 追加 3 条带 topic_id 的消息
|
// 追加 3 条带 topic_id 的消息
|
||||||
for content in ["m1", "m2", "m3"] {
|
for content in ["m1", "m2", "m3"] {
|
||||||
store
|
store
|
||||||
.append_message_with_topic(
|
.append_message_with_topic(&session.id, Some(&topic.id), &ChatMessage::user(content))
|
||||||
&session.id,
|
|
||||||
Some(&topic.id),
|
|
||||||
&ChatMessage::user(content),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,9 +708,7 @@ fn test_get_topic_message_count_uses_count_query() {
|
|||||||
assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 3);
|
assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 3);
|
||||||
|
|
||||||
// 另一个 topic 的计数应为 0(隔离验证)
|
// 另一个 topic 的计数应为 0(隔离验证)
|
||||||
let other_topic = store
|
let other_topic = store.create_topic(&session.id, "topic-2", None).unwrap();
|
||||||
.create_topic(&session.id, "topic-2", None)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(store.get_topic_message_count(&other_topic.id).unwrap(), 0);
|
assert_eq!(store.get_topic_message_count(&other_topic.id).unwrap(), 0);
|
||||||
|
|
||||||
// 不存在的 topic_id 返回 0
|
// 不存在的 topic_id 返回 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user