Skip to content

Commit e19984f

Browse files
committed
fix(review): 任务索引元数据按载荷追踪保留(行漂移不丢改期)
1 parent 17adf14 commit e19984f

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

‎app/src-tauri/src/db_task_index.rs‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,25 @@ pub fn rebuild_note_tasks(conn: &Connection, note_id: i64, content: &str) {
6666

6767
fn rebuild_inner(conn: &Connection, note_id: i64, content: &str) -> Result<()> {
6868
let now = crate::db::unix_seconds();
69-
// 重扫前读取旧行元数据(plan_date/disposition/created_at)——行号漂移由
70-
// (note_id,line_no) 键吸收;改期/纠偏为索引列元数据,不得被每次正文保存
71-
// 的重扫抹除(审查高-1:先删后插必须回填,否则计划分区/徽标失真)
72-
let mut meta: std::collections::HashMap<i64, (Option<i64>, Option<String>, i64)> = Default::default();
69+
// 重扫前读取旧行元数据(plan_date/disposition/created_at)——正文保存不得
70+
// 抹除索引列元数据(审查高-1)。匹配键=任务载荷优先(行号漂移由载荷追踪
71+
// 吸收:同一条任务挪行后仍保留改期/纠偏),行号仅作兜底。
72+
let mut meta_rows: Vec<(i64, String, Option<i64>, Option<String>, i64)> = Vec::new();
7373
{
7474
let mut stmt = conn.prepare(
75-
"SELECT line_no, plan_date, disposition, created_at FROM task_index WHERE note_id = ?1",
75+
"SELECT line_no, task_text, plan_date, disposition, created_at FROM task_index WHERE note_id = ?1",
7676
)?;
7777
let mapped = stmt.query_map(params![note_id], |r| {
7878
Ok((
7979
r.get::<_, i64>(0)?,
80-
r.get::<_, Option<i64>>(1)?,
81-
r.get::<_, Option<String>>(2)?,
82-
r.get::<_, i64>(3)?,
80+
r.get::<_, String>(1)?,
81+
r.get::<_, Option<i64>>(2)?,
82+
r.get::<_, Option<String>>(3)?,
83+
r.get::<_, i64>(4)?,
8384
))
8485
})?;
8586
for row in mapped {
86-
let (line_no, plan_date, disposition, created_at) = row?;
87-
meta.insert(line_no, (plan_date, disposition, created_at));
87+
meta_rows.push(row?);
8888
}
8989
}
9090
conn.execute("DELETE FROM task_index WHERE note_id = ?1", params![note_id])?;
@@ -98,8 +98,12 @@ fn rebuild_inner(conn: &Connection, note_id: i64, content: &str) -> Result<()> {
9898
TaskStatus::Todo => "todo",
9999
TaskStatus::Done => "done",
100100
};
101-
let (plan_date, disposition, created_at) = match meta.get(&(line_no as i64)) {
102-
Some((pd, dp, ca)) => (*pd, dp.clone(), *ca),
101+
let old = meta_rows
102+
.iter()
103+
.find(|(_, text, _, _, _)| *text == p.payload)
104+
.or_else(|| meta_rows.iter().find(|(ln, _, _, _, _)| *ln == line_no as i64));
105+
let (plan_date, disposition, created_at) = match old {
106+
Some((_, _, pd, dp, ca)) => (*pd, dp.clone(), *ca),
103107
None => (None, None, now),
104108
};
105109
stmt.execute(params![

0 commit comments

Comments
 (0)