D
D
Denis Korneev2020-05-16 15:50:10
JavaScript
Denis Korneev, 2020-05-16 15:50:10

Disk write optimization. When to store data in localForage?

I have an SPA running in Elecron that receives messages from the user from the VKontakte servers.
I need to somehow save these messages, I decided to use localForage, a library that provides functions like in localStorage only for working with IndexedDB(setItem(key, val), getItem(key, val)) and so on.
I'm connected to a longPoll update server, and when a new message arrives in a chat with a certain person, I need to save it to my hard disk, but the problem is that I can't do this with a specific message, I need to take all the messages, add a new one to them , and then save it all, with a constant stream of new messages, this leads to constant loads on the hard disk.
How to solve this problem? DB solve these problems, if so, which one to choose? Or try using node fs?
But with node fs, it’s also a question, if we JSON.stringify(message array) and then write it to a text file, then we also lose the ability to add new messages there one at a time, you only need JSON.parse(file) and then combine it all and write down.
I'm at a loss as to how best to proceed with this. Perhaps I should write data to disk only at certain intervals? Or should I save when I exit the app? Then the question arises with the unexpected closing of the application.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2020-05-16
@Orland25565

but the problem is that I can't do this with a specific message, I need to take all the messages, add a new one to them, and then save it all, with a constant stream of new messages, this leads to constant loads on the hard disk.
Here's the answer ... Keep the message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question