Import docx as persisted ydoc

hi,
i try to import docx with the following code:

let doc = utils.getYDoc(docName, true)
let ytext=doc.getText(‘text1’)
//convert docx to ytext

ytext.insert(0,‘doc5.paragraph1’)

//persist to leveldb
let db=utils.getPersistence()
const newUpdates = Y.encodeStateAsUpdate(doc)
db.provider.storeUpdate(docName, newUpdates)

currently it works.

i want to know if this is the correct way or there are more effecient/correct ways?
thanks.

after some debug, the above naive method is too expensive for importing.
are there any api for converting Delta to StateVector which can be stored in and retrieved from db? or are there some efficient way to bulk convert to ydoc from other formats say markdown/docx?
thanks.

any advice/hint?
thanks.

There is documentation for this here: Document Updates - Yjs Docs

I advise you to explore the code examples. Usually, you don’t want to store the whole document on every update. The documentation explains more efficient alternatives.