-
Notifications
You must be signed in to change notification settings - Fork 67
Remove document from synchronizer when document is removed from repo #423
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
base: main
Are you sure you want to change the base?
Changes from all commits
300dee4
ede14da
9417df6
b7930a9
5653fe4
1d401a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,10 +138,15 @@ export class CollectionSynchronizer extends Synchronizer { | |
}) | ||
} | ||
|
||
// TODO: implement this | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
/** Removes a document and stops synchronizing them */ | ||
removeDocument(documentId: DocumentId) { | ||
throw new Error("not implemented") | ||
log(`removing document ${documentId}`) | ||
const docSynchronizer = this.docSynchronizers[documentId] | ||
if (docSynchronizer !== undefined) { | ||
this.peers.forEach(peerId => docSynchronizer.endSync(peerId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
delete this.docSynchronizers[documentId] | ||
delete this.#docSetUp[documentId] | ||
} | ||
|
||
/** Adds a peer and maybe starts synchronizing with them */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,27 @@ describe("CollectionSynchronizer", () => { | |
|
||
setTimeout(done) | ||
})) | ||
|
||
it("removes document", () => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for including a test. @georgewsu can you think of a way we can test the memory usage, since that's a key motivation here? |
||
new Promise<void>((done, reject) => { | ||
const handle = repo.create() | ||
synchronizer.addDocument(handle) | ||
synchronizer.addPeer("peer1" as PeerId) | ||
// starts synchronizing document to peer | ||
synchronizer.once("message", event => { | ||
const { targetId, documentId } = event as SyncMessage | ||
assert(targetId === "peer1") | ||
assert(documentId === handle.documentId) | ||
done() | ||
}) | ||
// no message should be sent after removing document | ||
synchronizer.once("message", () => { | ||
reject(new Error("Should not have sent a message")) | ||
}) | ||
assert(synchronizer.docSynchronizers[handle.documentId] !== undefined) | ||
synchronizer.removeDocument(handle.documentId) | ||
assert(synchronizer.docSynchronizers[handle.documentId] === undefined) | ||
// removing document again should not throw an error | ||
synchronizer.removeDocument(handle.documentId) | ||
})) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added call to delete from progressCache