简体   繁体   中英

Saving content as JSON to a database in real time

I have a text editor built on Tiptap that sends its content as JSON to a API which saves it to a mongoDB database. I have a timeout on it so it only sends a request after the user has stopped typing for 1000ms.

Currently it sends the entire document in the request body making it very taxing performance-wise so I'm trying to figure out a way to identify the parts that have been changed, and only send the parts that have been changed in my request body.

Because the content is being saved in JSON I've been trying to find the index of the node so I can update said node, but I haven't been able to find a clear cut way of doing it. I've also been looking into Steps from the prosemirror docs but I can't figure out a way of implementing steps into the JSON content saved to the DB

I've tried assigning uuids to each node as an attribute, to later iterate through the JSON saved in the database but it seems highly inefficient and I'd really love some input as to how:

  1. this could be achieved
  2. OR in the case that my approach is entirely out of convention, how content is usually saved to a database

if you want save your content real time you have to do more efficient that i will say some solutions for this:

  • create a de-bouncer to save your content in data base after while user stop typing or create save button.
  • use UDP instead of TCP it's faster but its not safe then maybe u will lost some data
  • use RDB instead of Mongo like Redis to store data faster if you have prob in saving data then you can save you data after a while in you main database (mongoDB)
  • in order to get real time chat and and real time saving data base use web-socket instead of sending request and waiting for handshake with this approach you can show the text data with web socket in client side and also send data into Redis to save temporary in RDB then save in Mongo db for permanently store.

for more performance and more safety is better to combine all these struct er together. these solution are my personal experience and i do it before.

I'm new to Tiptap and ProseMirror but:

You might want to look at Tiptap's Collaborative editing .

You could intercept the transactions beeing sent to the socket server (It should only contain the updated part, I guess its only sends Prose Mirror transaction). And I guess that, since the socket server is able to send full document to new connected user, It is always able to reconstruct the full document. So you potentially could replace your system, with hocuspocus.

PS: it is beeing developped right now, so you have to pay a little to have access to it. But it could save you time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM