Skip to content

Commit 6e3eecd

Browse files
committed
incremental: subsequent result records should not store parent references
as memory then cannot be freed
1 parent 8cfa3de commit 6e3eecd

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/execution/IncrementalPublisher.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ export class IncrementalPublisher {
276276

277277
publishInitial() {
278278
for (const child of this._initialResult.children) {
279+
if (child.filtered) {
280+
continue;
281+
}
279282
this._publish(child);
280283
}
281284
}
@@ -299,11 +302,7 @@ export class IncrementalPublisher {
299302
}
300303

301304
this._delete(child);
302-
const parent =
303-
child.parentContext === undefined
304-
? this._initialResult
305-
: child.parentContext;
306-
parent.children.delete(child);
305+
child.filtered = true;
307306

308307
if (isStreamItemsRecord(child)) {
309308
if (child.asyncIterator !== undefined) {
@@ -364,6 +363,9 @@ export class IncrementalPublisher {
364363
for (const incrementalDataRecord of completedRecords) {
365364
const incrementalResult: IncrementalResult = {};
366365
for (const child of incrementalDataRecord.children) {
366+
if (child.filtered) {
367+
continue;
368+
}
367369
this._publish(child);
368370
}
369371
if (isStreamItemsRecord(incrementalDataRecord)) {
@@ -435,20 +437,16 @@ export class DeferredFragmentRecord {
435437
label: string | undefined;
436438
path: Array<string | number>;
437439
data: ObjMap<unknown> | null;
438-
parentContext: IncrementalDataRecord | undefined;
439440
children: Set<IncrementalDataRecord>;
440441
isCompleted: boolean;
441-
constructor(opts: {
442-
label: string | undefined;
443-
path: Path | undefined;
444-
parentContext: IncrementalDataRecord | undefined;
445-
}) {
442+
filtered: boolean;
443+
constructor(opts: { label: string | undefined; path: Path | undefined }) {
446444
this.label = opts.label;
447445
this.path = pathToArray(opts.path);
448-
this.parentContext = opts.parentContext;
449446
this.errors = [];
450447
this.children = new Set();
451448
this.isCompleted = false;
449+
this.filtered = false;
452450
this.data = null;
453451
}
454452
}
@@ -459,25 +457,24 @@ export class StreamItemsRecord {
459457
label: string | undefined;
460458
path: Array<string | number>;
461459
items: Array<unknown> | null;
462-
parentContext: IncrementalDataRecord | undefined;
463460
children: Set<IncrementalDataRecord>;
464461
asyncIterator: AsyncIterator<unknown> | undefined;
465462
isCompletedAsyncIterator?: boolean;
466463
isCompleted: boolean;
464+
filtered: boolean;
467465
constructor(opts: {
468466
label: string | undefined;
469467
path: Path | undefined;
470468
asyncIterator?: AsyncIterator<unknown>;
471-
parentContext: IncrementalDataRecord | undefined;
472469
}) {
473470
this.items = null;
474471
this.label = opts.label;
475472
this.path = pathToArray(opts.path);
476-
this.parentContext = opts.parentContext;
477473
this.asyncIterator = opts.asyncIterator;
478474
this.errors = [];
479475
this.children = new Set();
480476
this.isCompleted = false;
477+
this.filtered = false;
481478
this.items = null;
482479
}
483480
}

0 commit comments

Comments
 (0)