Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent deregisterElement from deregistering twice in nested object #716

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/document/crdt/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,15 @@ export class CRDTRoot {
this.elementPairMapByCreatedAt.delete(createdAt);
this.removedElementSetByCreatedAt.delete(createdAt);
count++;

if (elem instanceof CRDTContainer) {
elem.getDescendants((e) => {
deregisterElementInternal(e);
return false;
});
}
};

deregisterElementInternal(element);
if (element instanceof CRDTContainer) {
element.getDescendants((e) => {
deregisterElementInternal(e);
return false;
});
}

return count;
}
Expand Down
12 changes: 12 additions & 0 deletions test/integration/gc_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,16 @@ describe('Garbage Collection', function () {
await client1.deactivate();
await client2.deactivate();
});
it('garbage collection test for nested object', async function ({ task }) {
hackerwins marked this conversation as resolved.
Show resolved Hide resolved
type TestDoc = { shape?: { point?: { x?: number; y?: number } } };
const docKey = toDocKey(`${task.name}-${new Date().getTime()}`);
const doc = new yorkie.Document<TestDoc>(docKey);

doc.update((root) => {
root.shape = { point: { x: 0, y: 0 } };
delete root.shape;
});
assert.equal(doc.getGarbageLen(), 4); // shape, point, x, y
assert.equal(doc.garbageCollect(MaxTimeTicket), 4); // The number of GC nodes must also be 4.
});
});