I have a contenteditable div where users can enter up to about 20kb of text. As they’re typing I want to keep autosaving that div to a mysql table so that they can later retrieve that text on their phone, tablet etc. So far I’ve been simply autosaving every 20 seconds by taking the whole text block and doing an update to the row in my table that holds that text.
I realize that method is really inefficient and won’t work once my user base grows. Is there a better way to do this? E.g, somehow take a diff between the original text and what changed and save only that? Use node.js? If you’ve got some idea, let me know. Thanks.
Not all texts will be 20kb, so there doesn’t need to be a direct problem. You could also choose to autosave less often, and you can autosave to a session too, and only write to the database less frequently.
You could calculate the differences between the stored version (which can be kept in the session too) and the typed version. The advantage is that you don’t have to use the database so often, but processing will become harder, so the load on your webserver will increase too.
I’d maybe choose to do autosaves to a memory table (you can choose the storage type in MySQL), and write a separate process/cron job, that updates the physical table in bulk on regular intervals.