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: Update storage for inbound_group_sessions #2885

Merged
merged 8 commits into from
Nov 30, 2023

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Nov 25, 2023

Currently, querying for inbound group sessions which need backing up is very
inefficient: we have to search through the whole list.

Here, we change the way they are stored so that we can maintain an index of the
ones that need a backup.

Fixes: element-hq/element-web#26488
Fixes: #2877

@richvdh richvdh requested a review from a team as a code owner November 25, 2023 02:06
@richvdh richvdh requested review from poljar and removed request for a team November 25, 2023 02:06
@richvdh richvdh force-pushed the rav/fix_igs_query_for_backups branch from 08d5192 to 63ae9f1 Compare November 25, 2023 02:11
@richvdh richvdh force-pushed the rav/prepare_for_igs_migration branch from c8688ce to a4c46b1 Compare November 27, 2023 13:32
Base automatically changed from rav/prepare_for_igs_migration to main November 27, 2023 15:59
Currently, querying for inbound group sessions which need backing up is very
inefficient: we have to search through the whole list.

Here, we change the way they are stored so that we can maintain an index of the
ones that need a backup.
@richvdh richvdh force-pushed the rav/fix_igs_query_for_backups branch from 63ae9f1 to 0344d6a Compare November 27, 2023 16:01
Copy link

codecov bot commented Nov 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bfe7946) 82.66% compared to head (2c191d6) 82.66%.
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2885   +/-   ##
=======================================
  Coverage   82.66%   82.66%           
=======================================
  Files         216      216           
  Lines       22182    22182           
=======================================
  Hits        18337    18337           
  Misses       3845     3845           

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

@bnjbvr bnjbvr changed the title indexeddb: Update storage for inbound_group_sessions indexeddb: Update storage for inbound_group_sessions Nov 28, 2023
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 writing tests. Mostly asking for small clarifications here and there.

crates/matrix-sdk-indexeddb/src/crypto_store/migrations.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-indexeddb/src/crypto_store/migrations.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-indexeddb/src/crypto_store/migrations.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-indexeddb/src/crypto_store/migrations.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs Outdated Show resolved Hide resolved
let session = InboundGroupSession::from_pickle(pickled_session)
.map_err(|e| IndexeddbCryptoStoreError::CryptoStoreError(e.into()))?;

// Although a "backed up" flag is stored inside the `data`, it is not maintained
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear what data is referring to, here? (I suppose the idb_object.data — maybe a sign that the data field should be named something else)

Also: why not maintain the backed_up flag when resetting the backups? At a first glance, it seems that resetting the backups is the least frequent, when deserializing an inbound group session would be quite frequent. And I'm wary of adding logic to a deserialization function; ideally we would not need to have to remember that we can't just plain deserialize-and-build-from-pickle as we consistently do elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not clear what data is referring to, here? (I suppose the idb_object.data — maybe a sign that the data field should be named something else)

Renamed, as below.

Also: why not maintain the backed_up flag when resetting the backups? At a first glance, it seems that resetting the backups is the least frequent, when deserializing an inbound group session would be quite frequent.

Well, because it would involve decrypting, deserializing, updating, re-serializing, and re-encrypting each of possibly hundreds of thousands of pickled sessions. I don't think that's a price worth paying to simplify the code a bit. (The decryption and encryption bits are particularly expensive.)

Ideally we would not need to have to remember that we can't just plain deserialize-and-build-from-pickle as we consistently do elsewhere.

I don't disagree, but any deserialization is necessarily going to happen via deserialize_inbound_group_session. In other words, the awkwardness is constrained to one particular function, and I don't really see that we'd need to remember it elsewhere.

crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-indexeddb/src/crypto_store/migrations.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr removed the request for review from poljar November 28, 2023 14:54
@richvdh richvdh requested a review from bnjbvr November 28, 2023 17:39
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!

@bnjbvr bnjbvr merged commit 1fcd5af into main Nov 30, 2023
35 checks passed
@bnjbvr bnjbvr deleted the rav/fix_igs_query_for_backups branch November 30, 2023 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants