Skip to content

Commit 71c4dc3

Browse files
committed
fix: invalidate result cache on append + complete lazy.ts hash key
- LocalExecutor.append() now clears resultCache for the mutated table - queryHashKey() was missing filterGroups, distinct, windows, computedColumns, setOperation, subqueryIn, and version fields
1 parent f28c126 commit 71c4dc3

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/lazy.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,64 @@ export function queryHashKey(desc: QueryDescriptor): string {
198198
parts.push(`g:${[...desc.groupBy].sort().join(",")}`);
199199
}
200200

201+
// Filter groups (OR)
202+
if (desc.filterGroups && desc.filterGroups.length > 0) {
203+
for (let gi = 0; gi < desc.filterGroups.length; gi++) {
204+
const grp = desc.filterGroups[gi];
205+
for (const f of grp) parts.push(`fg${gi}:${f.column}:${f.op}:${stringifyValue(f.value)}`);
206+
}
207+
}
208+
209+
// Distinct
210+
if (desc.distinct && desc.distinct.length > 0) {
211+
parts.push(`d:${[...desc.distinct].sort().join(",")}`);
212+
}
213+
201214
// Vector search
202215
if (desc.vectorSearch) {
203216
const vs = desc.vectorSearch;
204217
parts.push(`v:${vs.column}:${vs.topK}:${Array.from(vs.queryVector).join(",")}`);
205218
}
206219

220+
// Windows
221+
if (desc.windows && desc.windows.length > 0) {
222+
for (const w of desc.windows) {
223+
let wp = `w:${w.fn}:${w.alias}:${w.column ?? ""}`;
224+
if (w.partitionBy?.length) wp += `:pb=${w.partitionBy.join(",")}`;
225+
if (w.orderBy?.length) wp += `:ob=${w.orderBy.map(o => o.column + o.direction).join(",")}`;
226+
if (w.frame) wp += `:fr=${w.frame.type}:${w.frame.start}:${w.frame.end}`;
227+
parts.push(wp);
228+
}
229+
}
230+
231+
// Computed columns
232+
if (desc.computedColumns && desc.computedColumns.length > 0) {
233+
for (const cc of desc.computedColumns) parts.push(`cc:${cc.alias}`);
234+
}
235+
236+
// Set operation
237+
if (desc.setOperation) {
238+
parts.push(`so:${desc.setOperation.mode}:${queryHashKey(desc.setOperation.right as QueryDescriptor)}`);
239+
}
240+
241+
// Subquery IN
242+
if (desc.subqueryIn) {
243+
for (const sq of desc.subqueryIn) {
244+
parts.push(`sq:${sq.column}:${[...sq.valueSet].sort().join(",")}`);
245+
}
246+
}
247+
207248
// Join
208249
if (desc.join) {
209250
const j = desc.join;
210251
parts.push(`j:${j.leftKey}:${j.rightKey}:${j.type ?? "inner"}:${queryHashKey(j.right as QueryDescriptor)}`);
211252
}
212253

254+
// Version
255+
if (desc.version !== undefined) {
256+
parts.push(`ver:${desc.version}`);
257+
}
258+
213259
return parts.join("|");
214260
}
215261

src/local-executor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ export class LocalExecutor implements QueryExecutor {
167167
// Write _latest
168168
await fs.writeFile(latestPath, String(newVersion));
169169

170-
// Invalidate meta cache
170+
// Invalidate meta + result caches
171171
this.metaCache.delete(tablePath);
172172
this.datasetCache.delete(tablePath);
173+
this.resultCache.invalidateByPrefix(`qr:${tablePath}:`);
173174

174175
return {
175176
version: newVersion,

0 commit comments

Comments
 (0)