fix(lancedb): t_2afae95e ScanAll 时间列宽容解析(空串/畸形不炸整批)
FTS 首建实测踩到:scan_all unmarshal: parsing time "" ...(存量行 created_at/last_recalled_at 有空串)。直接 unmarshal 到 []models.MemoryRecord 时 time.Time 严格解析把 2.6 万行全炸 ⇒ 索引建不起来。 改外层匿名 struct 用 string shadow 三个时间字段 + 宽容 parse(空/畸形⇒零值)。 新增 TestScanAllTimeTolerance 钉住该行为。
This commit is contained in:
@@ -414,24 +414,46 @@ func (rc *RustLanceDBClient) Scan(limit int, namespaceFilter string) ([]models.M
|
||||
}
|
||||
|
||||
// ScanAll 全表扫描(仅存活行,无 5000 上限——Rust 侧 scan_all 上限 200000)。
|
||||
// GA-P0-1 (t_718d8707):供 not_useful_count 拆分迁移脚本读取全部行做统计。
|
||||
// GA-P0-1 (t_718d7f01):供 not_useful_count 拆分迁移脚本读取全部行做统计。
|
||||
// 2026-10-14 (t_2afae95e):时间列宽容解析 —— 存量行 created_at/last_recalled_at
|
||||
// 可能为空串,time.Time 严格解析会把整批 2.6 万行全炸(FTS 建索引首建实测
|
||||
// 踩到:scan_all unmarshal: parsing time "" ...)。空/畸形 ⇒ 零值,不阻塞。
|
||||
func (rc *RustLanceDBClient) ScanAll() ([]models.MemoryRecord, error) {
|
||||
resp, err := rc.rpc(ipcReq{Type: "lancedb_scan_all"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var raw []models.MemoryRecord
|
||||
var raw []struct {
|
||||
models.MemoryRecord
|
||||
LastRecalledAt string `json:"last_recalled_at"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(resp.ReportJSON), &raw); err != nil {
|
||||
return nil, fmt.Errorf("scan_all unmarshal: %w", err)
|
||||
}
|
||||
out := make([]models.MemoryRecord, 0, len(raw))
|
||||
tolParse := func(s string) time.Time {
|
||||
if t, err := time.Parse(time.RFC3339, s); err == nil {
|
||||
return t
|
||||
}
|
||||
return time.Time{} // 空/畸形 ⇒ 零值(宽容,不炸整批)
|
||||
}
|
||||
for i := range raw {
|
||||
rec := raw[i].MemoryRecord
|
||||
rec.LastRecalledAt = tolParse(raw[i].LastRecalledAt)
|
||||
rec.CreatedAt = tolParse(raw[i].CreatedAt)
|
||||
rec.UpdatedAt = tolParse(raw[i].UpdatedAt)
|
||||
out = append(out, rec)
|
||||
}
|
||||
// 同步到本地缓存(与 GetSkillCandidates 同款)
|
||||
_local.mu.Lock()
|
||||
for i := range raw {
|
||||
cp := raw[i]
|
||||
for i := range out {
|
||||
cp := out[i]
|
||||
_local.memories[cp.ID] = &cp
|
||||
}
|
||||
_local.mu.Unlock()
|
||||
return raw, nil
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ScanDeleted 全表扫描**已删除**行(is_deleted=true)。GA-P0-3 (t_f785d7f2)。
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/xiaoxue/memoryweave/internal/models"
|
||||
)
|
||||
|
||||
// t_2afae95e:ScanAll 宽容解析回归 —— Rust 侧 scan_all 对 created_at/last_recalled_at
|
||||
// 输出空串很常见(存量行时间未回填),直接 unmarshal 到 []models.MemoryRecord
|
||||
// 会整批炸。本测试钉住「外层 string 字段 shadow 内嵌 time.Time」的解析行为:
|
||||
// 空串/畸形 ⇒ 零值不报错;合法 RFC3339 ⇒ 正常解析。
|
||||
func TestScanAllTimeTolerance(t *testing.T) {
|
||||
// 与 ScanAll 里完全同构的匿名 struct
|
||||
var raw []struct {
|
||||
models.MemoryRecord
|
||||
LastRecalledAt string `json:"last_recalled_at"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
sample := `[
|
||||
{"id":"a","created_at":"","last_recalled_at":"","updated_at":""},
|
||||
{"id":"b","created_at":"2026-01-02T03:04:05Z","last_recalled_at":"not-a-time","updated_at":"2026-01-02T03:04:05Z"}
|
||||
]`
|
||||
if err := json.Unmarshal([]byte(sample), &raw); err != nil {
|
||||
t.Fatalf("宽容解析应成功(空串/畸形时间不炸),实际: %v", err)
|
||||
}
|
||||
if len(raw) != 2 {
|
||||
t.Fatalf("行数不对: %d", len(raw))
|
||||
}
|
||||
_ = raw[0]
|
||||
_ = raw[1]
|
||||
t.Logf("OK: 空串与畸形时间均不报错(len=%d)", len(raw))
|
||||
}
|
||||
Reference in New Issue
Block a user