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

DRAFT: feat(25903): Move state management from storage.local to IndexedDB #27344

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

DDDDDanica
Copy link
Contributor

@DDDDDanica DDDDDanica commented Sep 23, 2024

Description

We currently rely on the Chrome Storage API to maintain state, but after evaluating performance and reliability, we’ve decided to transition to the IndexedDB API. This PR introduces a new ExtensionStore class that wraps IndexedDB, which has been fully implemented and tested. The existing reliance on storage.local has been replaced, accompanied by updated unit tests to ensure smooth functionality. Additionally, the ReadOnlyNetworkStore, previously used for testing, has been migrated to TypeScript.

Previously, using chrome.storage.local.get(console.log) in the DevTools console allowed us to easily retrieve the local storage data. Now, with the transition to IndexedDB, we can either

  • use a script to access it, NOTE: This cannot be performed in production code due to lavamoat limitation
indexedDB.open('ExtensionStore').onsuccess = function (event) {
  const db = event.target.result;
  const transaction = db.transaction('ExtensionStore', 'readonly');
  const objectStore = transaction.objectStore('ExtensionStore');
  objectStore.getAll().onsuccess = function (e) {
    console.log(e.target.result);
  };
};
  • or find the data within the Application tab in DevTools. (see recordings below)

Open in GitHub Codespaces

Related issues

Fixes: #25903

Manual testing steps

  1. Onboard extension
  2. Inspect chrome dev tools -> application -> indexDB -> extensionStore -> find the state there
  3. alternatively, chrome dev tools -> console ->
indexedDB.open('ExtensionStore').onsuccess = function (event) {
  const db = event.target.result;
  const transaction = db.transaction('ExtensionStore', 'readonly');
  const objectStore = transaction.objectStore('ExtensionStore');
  objectStore.getAll().onsuccess = function (e) {
    console.log(e.target.result);
  };
};

You can find the local state

Some other edge cases i want to cover:

  1. Perform an onboarding, indexedDB loaded
  2. Clear cache and hard reload, state is back
  3. Toggle off and on extension, state is back
  4. Delete storage by chrome.storage.local.clear(function() { console.log('All items have been removed from chrome.storage.local.'}); and refresh, state is back
  5. Delete storage by chrome.storage.local.clear, toggle extension, state is back

Screenshots/Recordings

Before

After

indexDB.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [512cab6]
Page Load Metrics (2009 ± 93 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16482503200519292
domContentLoaded16402380197018488
load16482491200919493
domInteractive146937157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 102 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 1.31 KiB (0.02%)

@DDDDDanica DDDDDanica force-pushed the feature/25903 branch 6 times, most recently from a5f5f56 to cf7325b Compare September 24, 2024 18:00
@metamaskbot
Copy link
Collaborator

Builds ready [cf7325b]
Page Load Metrics (1790 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16142104178010852
domContentLoaded1596197717509043
load16052117179011354
domInteractive14193453818
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 102 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 1.31 KiB (0.02%)

@davidmurdoch
Copy link
Contributor

Not sure who this question is for, but why do we think this is better/faster than chrome.storage.local? I know the linked issue says "We believe IndexedDB is more reliable and performant."... but who believes this and why?

@DDDDDanica DDDDDanica force-pushed the feature/25903 branch 3 times, most recently from ceb500f to 14f2f3b Compare September 26, 2024 13:47
@DDDDDanica DDDDDanica force-pushed the feature/25903 branch 3 times, most recently from eb35ea1 to 3edb91f Compare September 26, 2024 17:12
Copy link

sonarcloud bot commented Sep 26, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [0abff79]
Page Load Metrics (1815 ± 71 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint24921851731368177
domContentLoaded16042159177813866
load16122188181514771
domInteractive21159533215
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 102 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 2.08 KiB (0.03%)

@DDDDDanica DDDDDanica changed the title feat(25903): Move state management from storage.local to IndexedDB DRAFT: feat(25903): Move state management from storage.local to IndexedDB Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move state management from storage.local to IndexedDB
3 participants