-
Notifications
You must be signed in to change notification settings - Fork 260
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
Conversation
... and split it up into smaller functions
c0facf0
to
7a979a1
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
777f218
to
d2c2823
Compare
Turns out we don't need to implement `TryInto/TryFrom<JsValue>`, whihc saves a bunch of boilerplate.
d2c2823
to
c8688ce
Compare
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 👍)
¶ms, | ||
)?; | ||
|
||
if db.object_store_names().any(|n| n == "outgoing_secret_requests") { |
There was a problem hiding this comment.
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.
//! 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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! done in a4c46b1
// XXX Isn't there a way to do this that *doesn't* involve going via a JSON | ||
// string? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
c8688ce
to
a4c46b1
Compare
There was a problem hiding this 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 🙏
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.