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

Support listing and deleting wasm databases #2554

Merged
merged 4 commits into from
Aug 10, 2023
Merged

Conversation

simolus3
Copy link
Owner

@simolus3 simolus3 commented Aug 9, 2023

This adds the WasmDatabase.probe API, which can be used to list existing databases and delete them. It can also be used to open a database with a specific storage implementation which can be useful for apps needing a higher degree of customization.

@FaFre Feel free to take a look at the API to see if would satisfy your requirements. Unfortunately we can't efficiently iterate through IndexedDb databases, so we can only give you a complete list of OPFS databases.

@github-actions github-actions bot temporarily deployed to commit August 9, 2023 16:22 Inactive
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

🚀 Deployed on https://deploy-preview-2554--moor.netlify.app

@github-actions github-actions bot temporarily deployed to pull request August 9, 2023 16:26 Inactive
@simolus3 simolus3 merged commit 08fa630 into develop Aug 10, 2023
20 checks passed
@FaFre
Copy link
Contributor

FaFre commented Aug 10, 2023

Wow! That's great 🤩
It perfectly fits my needs, thanks for recognizing my feedback.

To give some feedback after switching to this implementation:

  • I created an extension to easily get my desired implementation:
extension _ on WasmProbeResult {
  WasmStorageImplementation? getPreferredImplementation() {
    if (availableStorages.contains(WasmStorageImplementation.opfsShared)) {
      return WasmStorageImplementation.opfsShared;
    } else if (availableStorages
        .contains(WasmStorageImplementation.opfsLocks)) {
      return WasmStorageImplementation.opfsLocks;
    }

    return null;
  }
}
  • I also decided to cache WasmProbeResult to open several databases from this instance. I hope to squeeze a bit of performance out of this, because my users will swap databases quite often.

@simolus3 simolus3 deleted the list-wasm-databases branch August 10, 2023 22:05
@simolus3
Copy link
Owner Author

Caching the result is probably a good call - I don't want to do it in drift because the list of existing databases could have changed, but it good to do it when you know they haven't. We have to re-run the whole feature detection chain every time which tries to spawn workers, so it's not exactly cheap (doing it once is fine though).

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

Successfully merging this pull request may close these issues.

2 participants