Implement hybrid IndexedDB SessionStorageManager to fix QuotaExceededError data loss#7678
Implement hybrid IndexedDB SessionStorageManager to fix QuotaExceededError data loss#7678lavjeetrai wants to merge 16 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7678 +/- ##
==========================================
+ Coverage 54.07% 54.15% +0.07%
==========================================
Files 171 172 +1
Lines 57098 57198 +100
==========================================
+ Hits 30878 30976 +98
- Misses 26220 26222 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
|
@walterbender @Ashutoshx7 @omsuneri I've tested this on my end, and it's working as expected. Whenever you have some time, could you please review it? Also, if you can think of any edge cases I should test, I'd be happy to check those as well. |
|
@lavjeetrai Since this PR also includes some controller refactoring beyond the IndexedDB changes, should we mention those changes in the PR description as well so the scope is accurately reflected? or diff PR for refactoring what's your take? |
|
Also, Is there a specific reason for choosing a 15-second autosave interval? |
|
@zealot-zew FYI |
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
|
@ssz2605 for refactoring part i will update the desc .thank u so much for giving ur time to review this and for 15 sec timing i thought that capturing playground data in minimum duration again would be good ...Is this a good thing what do u think ? |
|
@lavjeetrai Makes sense to reduce the potential data-loss window. I was mainly wondering whether 15 seconds was chosen based on any measurements or prior discussion, or if it's just an initial value. Since this changes the autosave frequency quite a bit (from 5 minutes), it would be good to document the rationale in the PR. |
|
Also changes looks in good direction now.. but I would like to have others opinion on this.. |
|
I think this is looking good. But we will need to wait to merge until after the upcoming release (hopefully this weekend) as it will need extensive testing. Also, can you confirm that whatever is currently in local storage will be migrated to indexDB so there is no data loss? |
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
Description
This PR replaces the fragile
localStoragemechanism for continuous autosaving with a robustIndexedDB-backed session manager. It resolvesQuotaExceededErrorcrashes on large projects and ensures no work is lost during unexpected reloads or tab closures.Key Features & Changes
1. IndexedDB & Session Management
SessionStorageManagerto handle asynchronous background backups to IndexedDB, completely bypassing the 5MBlocalStoragelimit for project auto-saves.beforeunloadevent to ensure any uncommitted, in-progress changes are synchronously saved to local session keys right before the browser tab is closed.2. Clean "Hard Refresh" (
Ctrl+Shift+R)Ctrl+Shift+R) that cleanly wipes the IndexedDB session and explicitly bypasses thebeforeunloadautosave.js/utils/sessionManager.js)IndexedDBto exclusively handle saving/loading massive session payloads asynchronously.sessionManager.test.js).js/activity.js)SessionStorageManagerin theActivityconstructor.__saveLocally()to gracefully handleQuotaExceededErrorsilently without crashing the app, while accurately saving aSESSION_TIMESTAMP.saveSessionAsync()to push massive payloads toIndexedDBwithout freezing the UI thread.loadStartto intelligently query bothlocalStorageandIndexedDBon boot, injecting whichever snapshot has the most recent timestamp.js/activity/idle-watcher.js)saveSessionAsync(), eliminating UI stutter on large projects.js/languagebox.js)await activity.saveSessionAsync()before callingwindow.location.reload(), guaranteeing no data is lost before the browser flushes memory.How it was verified locally:
Linting: Ran
npm run lint— verified 0 errors across all modified files to ensure strict code style compliance.Unit Testing: Ran
npm run test— verified all IndexedDB wrapper tests pass.Stress Testing (Language Switch Data Retention):
localStoragelimit) to intentionally trigger thelocalStorage quota exceededfallback.MusicBlocksSessionDBpopulated successfully in the browser's IndexedDB dev tools.Hybrid Fallback Testing: Created a tiny project, refreshed the page using F5 (which relies on the synchronous
beforeunloadlocalStorage save), and confirmed the project correctly restored using thelocalStoragefallback.Feature