| 1 | package historycatalog |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func BenchmarkWarmSearchTenThousandSources(b *testing.B) { |
| 10 | ctx := context.Background() |
| 11 | catalog, err := Open(ctx, Options{InMemory: true}) |
| 12 | if err != nil { |
| 13 | b.Fatal(err) |
| 14 | } |
| 15 | b.Cleanup(func() { _ = catalog.Close(context.Background()) }) |
| 16 | tx, err := catalog.db.Begin() |
| 17 | if err != nil { |
| 18 | b.Fatal(err) |
| 19 | } |
| 20 | for i := range 10_000 { |
| 21 | path := fmt.Sprintf("/sessions/session-%05d.jsonl", i) |
| 22 | if _, err := tx.Exec(`INSERT INTO history_sources(path,root,source,scope,workspace_root,health) VALUES(?,?,?,?,?,'ok')`, |
| 23 | path, "/sessions", "global", "global", ""); err != nil { |
| 24 | b.Fatal(err) |
| 25 | } |
| 26 | result, err := tx.Exec(`INSERT INTO history_documents(source_path,message_index,part_index,role,kind,tool_name,token_count) |
| 27 | VALUES(?,0,0,'user','user_text','',3)`, path) |
| 28 | if err != nil { |
| 29 | b.Fatal(err) |
| 30 | } |
| 31 | rowID, _ := result.LastInsertId() |
| 32 | if _, err := tx.Exec(`INSERT INTO history_fts(rowid,terms) VALUES(?,?)`, rowID, fmt.Sprintf("shared marker item%d", i)); err != nil { |
| 33 | b.Fatal(err) |
| 34 | } |
| 35 | } |
| 36 | if err := tx.Commit(); err != nil { |
| 37 | b.Fatal(err) |
| 38 | } |
| 39 | b.ResetTimer() |
| 40 | for range b.N { |
| 41 | if _, err := catalog.Search(ctx, SearchRequest{Query: "shared marker", Roots: []string{"/sessions"}, Limit: 50}); err != nil { |
| 42 | b.Fatal(err) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |