When loading documents we are saving any updates. This happens every time a user joins a document regardless of them making any document changes. See below:
// Load persisted document
const persistedYdoc = await ldb.getYDoc(docName);
const persistedStateVector = Y.encodeStateVector(persistedYdoc);
// Store any new updates
const latestUpdate = Y.encodeStateAsUpdate(ydoc);
const newUpdates = Y.diffUpdate(latestUpdate, persistedStateVector);
ldb.storeUpdate(docName, newUpdates);
Is there an easy way to check if the newUpdates
Uint8Array
contains content updates?
Without this we are filling our DB with useless updates that look like this:
value: Binary('AAA=', 0)
value: Binary('AAHn6L3BAgERAQ==', 0)
I have noticed that empty updates have a byteLength of 10.
Is it reliable to use this as the conditional?
if (newUpdates.byteLength > 10) {
ldb.storeUpdate(docName, newUpdates);
}