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

feat(crypto) Provide a method to check whether server backup exists without hitting the server every time #4356

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

andybalaam
Copy link
Member

@andybalaam andybalaam commented Nov 29, 2024

Part of element-hq/element-meta#2638

Provide fast_exists_on_server so we can call it when figuring out whether a UTD is expected. (Updated 2024-12-13 to reflect final implementation.)

Modify exists_on_server to cache the last value we received. Provide fetch_exists_on_server that explicitly makes a server request to get the latest information.

exists_on_server does not always provide a fully-correct answer, but it is a best effort that is much cheaper than the full fetch_exists_on_server which always makes a request to the server. Since we only plan to call the new method when reporting UTDs, for now, the negative consequence of an incorrect answer is only to report the wrong kind of UTD.

If you have suggestions for better ways to implement this, I am interested. I wish we didn't need to have a lock on the cached value but I couldn't see a better way.

@andybalaam andybalaam requested a review from a team as a code owner November 29, 2024 14:47
@andybalaam andybalaam requested review from bnjbvr and removed request for a team November 29, 2024 14:47
@andybalaam andybalaam marked this pull request as draft November 29, 2024 14:48
@andybalaam andybalaam removed the request for review from bnjbvr November 29, 2024 14:48
@andybalaam andybalaam force-pushed the andybalaam/refactor-exists-on-server-tests branch from 6f1588f to 944a1ba Compare December 3, 2024 14:41
Base automatically changed from andybalaam/refactor-exists-on-server-tests to main December 3, 2024 14:55
@andybalaam andybalaam force-pushed the andybalaam/fast-exists-on-server branch 2 times, most recently from eacb73b to fc8d59d Compare December 3, 2024 15:23
@andybalaam andybalaam marked this pull request as ready for review December 3, 2024 15:23
@andybalaam andybalaam requested a review from bnjbvr December 3, 2024 15:23
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.

Project coverage is 85.19%. Comparing base (e402ed4) to head (c37b485).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/test_utils/mocks.rs 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4356      +/-   ##
==========================================
- Coverage   85.20%   85.19%   -0.02%     
==========================================
  Files         281      281              
  Lines       30926    30963      +37     
==========================================
+ Hits        26352    26379      +27     
- Misses       4574     4584      +10     

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

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.

There are three things that are hard in computer science: invalidating caches, and off by ones. A few questions/suggestions below.

crates/matrix-sdk/src/encryption/backups/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/encryption/backups/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/encryption/backups/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/encryption/backups/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/encryption/backups/mod.rs Outdated Show resolved Hide resolved
@andybalaam andybalaam requested a review from bnjbvr December 6, 2024 13:33
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! Slightly concerned that the cached value may be outdated because another client erased the backup, but if you're fine with it, I'm fine with it :) (Isn't there a way to listen to some sync or to-device events, and realize the backup has been removed elsewhere?)

crates/matrix-sdk/src/test_utils/mocks.rs Outdated Show resolved Hide resolved
@andybalaam andybalaam force-pushed the andybalaam/fast-exists-on-server branch from 7c7d427 to f3926ca Compare December 9, 2024 15:09
@andybalaam andybalaam force-pushed the andybalaam/fast-exists-on-server branch from f3926ca to 7b5bd0e Compare December 9, 2024 15:17
@andybalaam andybalaam force-pushed the andybalaam/fast-exists-on-server branch from 888b959 to c37b485 Compare December 9, 2024 16:17
@andybalaam andybalaam enabled auto-merge (rebase) December 9, 2024 16:17
@andybalaam andybalaam merged commit 5721c36 into main Dec 9, 2024
40 checks passed
@andybalaam andybalaam deleted the andybalaam/fast-exists-on-server branch December 9, 2024 16:33
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