Commit 54580dd
authored
fix: worktree dedup and multi-project chunk storage (#142)
* fix: worktree dedup and multi-project chunk storage
Fix two issues that break content-hash dedup across git worktrees
sharing a PostgreSQL backend:
1. Files with documents but no chunks are permanently skipped.
When a prior indexing run creates document records but fails to
embed (e.g., missing API key), subsequent runs skip those files
because the mod-time gate and hash check don't verify chunk
existence. Fix: check len(doc.ChunkIDs) > 0 before skipping in
IndexAllWithBatchProgress and NeedsReindex.
2. Chunk IDs collide across projects sharing the same database.
Chunk IDs use relative paths (e.g., src/App.tsx_0). With the
primary key on just (id), ON CONFLICT upserts from a second
project overwrite the first project's chunks without updating
project_id — the second project ends up with 0 chunks.
Fix: migrate primary key to (project_id, id) and update the
ON CONFLICT clause to match.
Tested with 3 projects sharing one postgres instance:
- 100% content-hash cache hit rate for identical code
- ~9s per worktree (vs ~5min without cache)
- Each project gets its own chunk rows
* fix: update tests to match new ChunkIDs-aware skip logic
The indexer now calls GetDocument before the lastIndexTime gate and
requires doc.ChunkIDs to be non-empty for both the time-based and
hash-based skip paths. This prevents silently skipping files whose
prior indexing run created a document but failed to embed chunks.
Update tests to seed documents with ChunkIDs where the test expects
a skip, and remove assertions that GetDocument should not be called
(it is now called by design before the time check).1 parent 135f5bc commit 54580dd
File tree
5 files changed
+68
-26
lines changed- cli
- indexer
- store
5 files changed
+68
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
145 | 155 | | |
146 | 156 | | |
147 | 157 | | |
| |||
210 | 220 | | |
211 | 221 | | |
212 | 222 | | |
213 | | - | |
214 | | - | |
215 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
216 | 227 | | |
217 | 228 | | |
218 | 229 | | |
| |||
307 | 318 | | |
308 | 319 | | |
309 | 320 | | |
310 | | - | |
311 | | - | |
312 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
313 | 325 | | |
314 | 326 | | |
315 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
| |||
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
| 150 | + | |
149 | 151 | | |
150 | | - | |
| 152 | + | |
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
| |||
671 | 673 | | |
672 | 674 | | |
673 | 675 | | |
674 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
675 | 682 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | 70 | | |
62 | 71 | | |
63 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | 251 | | |
257 | 252 | | |
258 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
66 | 81 | | |
67 | 82 | | |
68 | 83 | | |
| |||
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
78 | 97 | | |
79 | 98 | | |
80 | 99 | | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
84 | 103 | | |
85 | | - | |
| 104 | + | |
86 | 105 | | |
87 | 106 | | |
88 | 107 | | |
| |||
0 commit comments