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

indexeddb: Tidy the migrations code #3095

Merged
merged 24 commits into from
Feb 7, 2024

Conversation

andybalaam
Copy link
Member

I found it quite hard to understand the Indexed DB schema migration code, so I did my best to tidy it.

Definitely review this commit by commit. Each commit is supposed to be quite trivial, but together they add up to code that I am able to understand much better.

@andybalaam andybalaam requested a review from a team as a code owner February 5, 2024 15:38
@andybalaam andybalaam requested review from bnjbvr and removed request for a team February 5, 2024 15:38
@andybalaam andybalaam force-pushed the andybalaam/indexeddb-tidy-migrations branch from 1f3a7ae to a92140f Compare February 5, 2024 15:57
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ae97772) 83.73% compared to head (78e3350) 83.73%.
Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3095   +/-   ##
=======================================
  Coverage   83.73%   83.73%           
=======================================
  Files         224      224           
  Lines       23536    23536           
=======================================
  Hits        19708    19708           
  Misses       3828     3828           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admire the effort to clean this tech debt. Thank you very much. The new code structure and new API is so much easier. Thanks!

@andybalaam andybalaam force-pushed the andybalaam/indexeddb-tidy-migrations branch from a648522 to e3c7e9d Compare February 7, 2024 12:24
@andybalaam andybalaam enabled auto-merge February 7, 2024 12:28
@andybalaam andybalaam merged commit 6a34f54 into main Feb 7, 2024
34 checks passed
@andybalaam andybalaam deleted the andybalaam/indexeddb-tidy-migrations branch February 7, 2024 12:41
andybalaam added a commit to matrix-org/matrix-rust-sdk-crypto-wasm that referenced this pull request Feb 7, 2024
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me, thank you for doing this!

One thing is that there is now an awful lot of opening and closing the DB going on, even in the simple case that there is no upgrade to be done, but maybe that's a quick enough operation, and there is no point optimising it prematurely.

@@ -86,6 +84,13 @@ pub async fn open_and_upgrade_db(
Ok(IdbDatabase::open_u32(name, 10)?.await?)
}

async fn db_version(name: &str) -> Result<u32, IndexeddbCryptoStoreError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be worth documenting that this function will create the db (at version 1) if it does not already exist.

@andybalaam
Copy link
Member Author

One thing is that there is now an awful lot of opening and closing the DB going on, even in the simple case that there is no upgrade to be done, but maybe that's a quick enough operation, and there is no point optimising it prematurely.

If there's no upgrade don't we only open it twice (to find the version, then to actually open it)?

If the DB is empty, we open and close a lot, but I haven't seen any performance problem from that so hopefully it's fine.

I'm not sure there is a good solution if we did find it is a problem in general, because need multiple separate schema migrations to happen, and the data migrations need to happen in between each one. We could special-case the empty DB case, but we'd only want to do that if we were convinced it caused a problem.

@richvdh
Copy link
Member

richvdh commented Feb 20, 2024

One thing is that there is now an awful lot of opening and closing the DB going on, even in the simple case that there is no upgrade to be done, but maybe that's a quick enough operation, and there is no point optimising it prematurely.

If there's no upgrade don't we only open it twice (to find the version, then to actually open it)?

If the DB is empty, we open and close a lot, but I haven't seen any performance problem from that so hopefully it's fine.

True. It's not as bad as I thought it was going to be.

I'm not sure there is a good solution if we did find it is a problem in general, because need multiple separate schema migrations to happen, and the data migrations need to happen in between each one. We could special-case the empty DB case, but we'd only want to do that if we were convinced it caused a problem.

I think we could approximately halve the number of opens by re-using db handles. But in any case, you're right that its an unnecessary optimisation.

@andybalaam
Copy link
Member Author

I think we could approximately halve the number of opens by re-using db handles. But in any case, you're right that its an unnecessary optimisation.

Ah right, by doing the data migration using the same DB handle as the schema upgrade we just did.

But yeah, probably no need.

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.

3 participants