Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple saves with writeDelay!=0 cause disk writes for every change #47

Open
iggu opened this issue Jun 30, 2021 · 1 comment
Open

Comments

@iggu
Copy link

iggu commented Jun 30, 2021

Looks like it is more correct to accumulate all changes and write them in a single write-to-disk and count timeout only from the last change (i.e. if timeout is set to 200 and multiple changes occur every 100 - then write when thery stop in a single bulk).
Or such an option would be appropriate alongside with writeDelay (say debounceDelay or something).


const trivialdb = require('trivialdb');
const tdbFslib = require('trivialdb/lib/fslib');

let wvi = 0, wvts = Date.now();
const tdb = tns.db("test", {
writeDelay: 200,
writeFunc: (path, str) => { console.log("W", ++wvi, wvts-Date.now(), str.length, "chars"); return tdbFslib.writeDB(path, str); }
});

tdb.loading.then(() => {
console.log('loaded.');
tdb.save({first: '1', last: 'a'})
.then(tdb.save.bind(tdb, {first: "2", last: "b"}, undefined))
.then(tdb.save.bind(tdb, {first: "3", last: "c"}, undefined))
.then(tdb.save.bind(tdb, {first: "4", last: "d"}, undefined))
;
});


loaded.
W 1 -203 85 chars
W 2 -208 168 chars
W 3 -210 251 chars
W 4 -212 334 chars

@Morgul
Copy link
Member

Morgul commented Aug 27, 2021

The design intention was definitely for that to behave like a debounce. I'd be more than happy to review a MR that fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants