-
Notifications
You must be signed in to change notification settings - Fork 23
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
Safe DB connection sharing #351
Conversation
44f707a
to
b6e9615
Compare
This is a beefy refactor - feel free to directly modify/merge if you are blocked on this/want to avoid conflicts |
Cleaner and so much better, nice job! |
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.
These changes look great. Think my only beef is with the name. Not sure slapping Xmtp onto the front of the name adds any useful context. Given this is the only DbConnection
anyone is using, I'd advocate for just calling it something straightforward.
This refactor aims to do the following:
&mut
refs or run-time via multipleRefCell
borrows)This is done by:
DbConnection
struct that wraps theRawDbConnection
in aRefCell
. TheDbConnection
uses interior mutability, therefore a non-mut reference to it can be freely shared as many times as desired.fetch
andstore
onto this struct. Additionally, add a method to this struct that allows external callers to execute raw queries via a closure. This ensures that theRawDbConnection
is only ever accessed internally withinDbConnection
, and uses function scope to make sure that borrows on theRefCell
are always returned before they are used again.RawDbConnection
is completely inaccessible outside ofEncryptedMessageStore
andDbConnection
. It is only possible for external callers to interact with the database viaDbConnection
, and all references toRawDbConnection
in the code have been replaced byDbConnection
.