Iraka-C / Skeeetch

A Web based sketch pad
Apache License 2.0
57 stars 4 forks source link

Asynchronous save request in IDB #10

Closed Iraka-C closed 3 years ago

Iraka-C commented 3 years ago

At present, every save call performs an IDB write. This is redundant especially when several writes occur on a same key (layer), where only the last write will be valid. All the write requests will be queued and performed one-by-one, which is time consuming.

Solution: make the write call as a request-check method. When one write call is performing, pend all the requests with a flag, and only keep the last request. (as you cannot halt the currently performing write action) Always perform ONLY the last write request to keep the highest write performance.

Iraka-C commented 3 years ago

Partially fixed by adding a calling queue and save check.

https://github.com/Iraka-C/Skeeetch/blob/b53015815be5d54f4ebfd6a9df57b24e47586ee5/gl/javascripts/my-library/my-forage.js#L194-L223

Iraka-C commented 3 years ago

TODO: change the Promise.then logic so that each Promise resolves after the contents' saved.