-
Notifications
You must be signed in to change notification settings - Fork 269
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
Persist filesystem changes after page refresh #19
Comments
Relevant: https://sqlite.org/wasm/doc/tip/about.md Specifically:
|
About persisting changes to the database, I recently learned about SQLite's Session extension.
I read about it in an article about someone developing an iOS app with a local SQLite database (full copy of the user data in the app itself).
Perhaps this could be a lighter-weight approach to saving SQLite state in browser local storage, by storing (and restoring) the session history instead of a snapshot of the whole database. |
IndexedDB is way too slow for persistence backend. Emscripten supports storing files in IndexedDb via IDBFS. I got a demo to work. If you run it and refresh the page, the initial // In loadPHPRuntime():
PHPRuntime.FS.mkdir('/offline');
PHPRuntime.FS.mount(PHPRuntime.FS.filesystems.IDBFS, {}, '/offline');
console.log(PHPRuntime.FS.readdir('/offline'));
const syncFs = (populate:boolean) => new Promise((resolve, reject) => {
console.log('Syncing FS...');
PHPRuntime.FS.syncfs(populate, function (err: Error) {
console.log('done', err);
if (err) {
reject(err);
} else {
resolve(true);
}
});
});
// Populate /offline from IndexedDb:
await syncFs(true);
PHPRuntime.FS.writeFile(
'/offline/test.txt',
new TextEncoder().encode('Hello world!')
);
// Write files from /offline to IndexedDb:
await syncFs(false); However, if you do that with WordPress files, each sync will take minutes: PHPRuntime.FS.mkdir('/wordpress');
PHPRuntime.FS.mount(PHPRuntime.FS.filesystems.IDBFS, {}, '/wordpress');
//await syncFs(true);
console.log(PHPRuntime.FS.readdir('/wordpress'));
for (const { default: loadDataModule } of dataDependenciesModules) {
loadDataModule(PHPRuntime);
}
if (!dataDependenciesModules.length) {
resolveDepsReady();
}
await depsReady;
await phpReady;
console.log(PHPRuntime.FS.readdir('/wordpress'));
await syncFs(false);
console.log(PHPRuntime.FS.readdir('/wordpress')); Perhaps storing just diffs would work better, but it sounds like a lot of work. Here's another ideaExporting and importing a zipped WordPress site works in a blink of an eye. Let's reuse it for persistence. |
More thoughts: The easiest way to implement this is through explicit buttons like:
These could be integrated with the version switchers and the In fact, we could retain the zip file in memory, keep track of all VFS writes, and update only specific files inside the archive. A few more ideas:
|
OPFS is a grate choice. you should look into switching to OPFS and JSPI |
@jimmywarting both are on the roadmap! JSPI will need to stabilize first - right now it’s chrome-only and limited to arm64 and x64. Also, we’ll need to build PHP with pthreads support as I think Emscripten can only support OPFS via threaded WASMFS (although I’d love to be wrong here). |
Done in #196 |
What problem is this issue trying to solve?
At the moment, all database changes and uploads are gone once the page is refreshed. Preserving them would be useful for courses, technical demos, even sharing a link to your changes.
What solution does this issue propose?
A few ideas:
localStorage
could store the binary contents of the.sqlite
file every few secondshttps://github.com/jlongster/absurd-sql can persist SQLite database in IndexedDBSee https://sqlite.org/wasm/doc/tip/about.mdThe text was updated successfully, but these errors were encountered: