IndexedDB onclose event handling #407
Replies: 3 comments
-
@GenovaEmpera I don't understand the real need. Would you like to keep the data even after manually deleting a database? |
Beta Was this translation helpful? Give feedback.
-
@aparzi The problem is, the user can flush their data and DB structure (objectStores) down the drain while clearing cache without even knowing it. So, when the DB objectStores do not restore after page reload, it becomes impossible to work with for obvious reasons. It's not really the stored data what's important here, but rather restoring DB structure (objectStores) in order to fill it with data once again. I could achieve that only through the aforementioned sequence. But not sure if it's the right solution. |
Beta Was this translation helpful? Give feedback.
-
@GenovaEmpera I understand the need, in reality I would tell you that I need to investigate the problem specifically and see how to best manage the solution. If you have implemented something at the moment, you can open a PR so as to view it and if necessary release a first implementation. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hello, everyone!
I've been using ngx-indexed-db for a while now in my Angular v17 app, and it's been well so far. I've got the config version 2 and in my migration function I simply loop through the config and create objectStores\Indexes. All's fine. But currently I've stambled on a problem when user manually deletes DB from indexedDB storage via:
Behaviour 1: The deleted DB stays deleted.
Behaviour 2: Sometimes it does reappear (in ~ 3secs) in features (that actively requests data from it) with the correct version (version 2), but its objects are missing.
Behaviour 3: Reloading the page may reinitialise it properly, but more times than not it ends up missing all objects. Maybe it's due to requesting data from DB (these requests fail, obviously) in parallel with it's
onupgradeneeded
event processing. Or something like the parallel upgrade problem with several webtabs open, I'm not sure. Guess it's due to user clearing DB like that its connection closes, but why does the deleted DB reappers just like that with objects missing after the connection closes?Anyways, in a service that manages ngx-indexed-db methods I tried opening the DB manually via
indexedDB.open(Config.name)
in order to listen toonclose
event (exactly the event when the DB closes unexpectedly) and reload the page when it triggered. Fearing that page reloading wouldn't reopen the DB properly with its objects intact (Behaviour 3), I tried the following sequence:init the app ->
indexedDB.open(Config.name)
(it opens with version 2) and listen toonclose
event -> user triggersonclose
event ->indexedDB.open(Config.name)
(it opens with version 1) -> reload the page -> triggeronupgradeneeded
inside ngx-indexed-db package.The sequence works and the pesky user cache clearing is dodged, but I still don't get if it's the right method, or why the DB behaves like that! I was wondering if there is a proper solution for this case?
Beta Was this translation helpful? Give feedback.
All reactions