Import docx as persisted ydoc

i try to import docx with the following code:

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


//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?

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?

any advice/hint?

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.