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: Groundwork for fixing inbound_group_session lookups #2884

Merged
merged 8 commits into from
Nov 27, 2023

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Nov 25, 2023

This is a set of non-functional changes which lay some groundwork in preparation for fixing element-hq/element-web#26488 (comment).

Hopefully each commit is reasonably self-explanatory.

@richvdh richvdh requested a review from a team as a code owner November 25, 2023 00:06
@richvdh richvdh requested review from bnjbvr and removed request for a team November 25, 2023 00:06
@richvdh richvdh force-pushed the rav/prepare_for_igs_migration branch from c0facf0 to 7a979a1 Compare November 25, 2023 00:12
Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ceeb5e7) 82.68% compared to head (a4c46b1) 82.69%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2884   +/-   ##
=======================================
  Coverage   82.68%   82.69%           
=======================================
  Files         216      216           
  Lines       22176    22176           
=======================================
+ Hits        18337    18338    +1     
+ Misses       3839     3838    -1     

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

@richvdh richvdh force-pushed the rav/prepare_for_igs_migration branch 2 times, most recently from 777f218 to d2c2823 Compare November 25, 2023 02:02
Turns out we don't need to implement `TryInto/TryFrom<JsValue>`, whihc saves a
bunch of boilerplate.
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Makes sense in general; just a bit hard to review, so I'm requesting to split the last commit that mixes code motion and changes to the moved code please.


/// Open the indexeddb with the given name, upgrading it to the latest version
/// of the schema if necessary.
pub async fn open_and_upgrade_db(name: &str) -> Result<IdbDatabase, DomException> {
Copy link
Member

Choose a reason for hiding this comment

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

(looking at the commit Move migration functions to a separate module and split it up into smaller functions)

In the future, can you avoid changes that both 1. move the code, 2. change the code, please? They make the review really hard. In this case the amount of code is small enough that it's not a big deal, but it takes quadratically more time than if the commit had been split into two smaller logical ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted, and agreed. Sorry about this!


fn create_stores_for_v2(db: &IdbDatabase) -> Result<(), DomException> {
// We changed how we store inbound group sessions, the key used to
// be a tuple of `(room_id, sender_key, session_id)` now it's a
Copy link
Member

Choose a reason for hiding this comment

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

(I noticed this comment has changed 👀, good job 👍)

&params,
)?;

if db.object_store_names().any(|n| n == "outgoing_secret_requests") {
Copy link
Member

Choose a reason for hiding this comment

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

I found the previous check with respect to the previous version number more obvious, but I think it should be equivalent, assuming atomic operations.

Comment on lines +15 to +25
//! Booleans don't work as keys in indexeddb (see [ECMA spec]), so instead we
//! serialize them as `0` or `1`.
//!
//! This module implements a custom serializer which can be used on `bool`
//! struct fields with:
//!
//! ```ignore
//! #[serde(with = "serialize_bool_for_indexeddb")]
//! ```
//!
//! [ECMA spec]: https://w3c.github.io/IndexedDB/#key
Copy link
Member

Choose a reason for hiding this comment

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

To make it easier for further uses of that functionality, instead of using the above serde annotation, would it make sense to use a newtype wrapper? Something like #[repr(transparent)] struct SerializableBool(bool), with From<bool>/Into<bool> impls, and that implements a custom serde::Serialize and serde::Deserialize?

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed, this doesn't quite work out as nicely as hoped due to the need to add .into calls everywhere.

@@ -138,6 +138,12 @@ impl From<indexed_db_futures::web_sys::DomException> for IndexeddbCryptoStoreErr
}
}

impl From<serde_wasm_bindgen::Error> for IndexeddbCryptoStoreError {
fn from(e: serde_wasm_bindgen::Error) -> Self {
IndexeddbCryptoStoreError::Json(serde::de::Error::custom(e.to_string()))
Copy link
Member

Choose a reason for hiding this comment

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

pre-existing: if that's not an API breaking change, could we rename the Json variant to Serialization?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! done in a4c46b1

Comment on lines +108 to +109
// XXX Isn't there a way to do this that *doesn't* involve going via a JSON
// string?
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, there's at least comment changes and code motion in this commit, and since it's a much bigger chunk than the previous, I'll request to split it into a code motion one first, and then the changes to the code as a second commit please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, sorry about this. The comments aren't particularly significant imho which is why I rolled them all together, but that was bad of me.

I've now split this into three separate commits.

Mostly, this means that we only need to hold the `store_cipher` in one place.
A couple of improvements and a couple of oddities I noted along the way.
@richvdh richvdh force-pushed the rav/prepare_for_igs_migration branch from c8688ce to a4c46b1 Compare November 27, 2023 13:32
@richvdh richvdh requested a review from bnjbvr November 27, 2023 14:30
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Thanks for splitting the commits, made the next round of review trivial 🙏

@richvdh richvdh merged commit bfe7946 into main Nov 27, 2023
35 checks passed
@richvdh richvdh deleted the rav/prepare_for_igs_migration branch November 27, 2023 15:59
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