-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactor aims to do the following: 1. Continue allow sharing DB connections between libxmtp logic and the OpenMLS keystore, including via transactions 2. Prevent errors arising from concurrent mutable access to this connection (whether at compile-time via multiple `&mut` refs or run-time via multiple `RefCell` borrows) 3. Simplify the DB interface This is done by: 1. Create an `DbConnection` struct that wraps the `RawDbConnection` in a `RefCell`. The `DbConnection` uses interior mutability, therefore a non-mut reference to it can be freely shared as many times as desired. 2. Move all DB operations, as well as `fetch` and `store` onto this struct. Additionally, add a method to this struct that allows external callers to execute raw queries via a closure. This ensures that the `RawDbConnection` is only ever accessed internally within `DbConnection`, and uses function scope to make sure that borrows on the `RefCell` are always returned before they are used again. 3. Use visibility to ensure that the `RawDbConnection` is completely inaccessible outside of `EncryptedMessageStore` and `DbConnection`. It is only possible for external callers to interact with the database via `DbConnection`, and all references to `RawDbConnection` in the code have been replaced by `DbConnection`.
- Loading branch information
1 parent
6626895
commit 099a525
Showing
22 changed files
with
533 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#[allow(clippy::module_inception)] | ||
#[cfg(test)] | ||
pub mod test_utils { | ||
use xmtp_proto::api_client::XmtpApiClient; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.