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: return transaction for workspace database operation #342

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

khorshuheng
Copy link
Contributor

Return transaction for workspace database operation, so that the callers can get the encoded update.

@appflowy appflowy merged commit d862b40 into main Dec 5, 2024
6 checks passed
@appflowy appflowy deleted the return-workspace-database-transaction branch December 5, 2024 05:36
.delete_database(&mut self.collab.transact_mut(), database_id);
pub fn delete_database(&mut self, database_id: &str) -> TransactionMut {
let mut txn = self.collab.transact_mut();
self.body.delete_database(&mut txn, database_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

As you can see here, you don't need to return transaction. You can just call self.collab.transact_mut + self.body.delete_database. Because both self.collab and self.body are split in every collab type, creating transaction should never be a problem.

@@ -56,7 +56,7 @@ impl WorkspaceDatabase {
/// Create a new [DatabaseMeta] for the given database id and view id
/// use [Self::update_database] to attach more views to the existing database.
///
pub fn add_database(&mut self, database_id: &str, view_ids: Vec<String>) {
pub fn add_database(&mut self, database_id: &str, view_ids: Vec<String>) -> TransactionMut {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to move add_database logic to body and provide transaction from outside. What if you want to call this method, while you already had transaction acquired? This would cause a deadlock.

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.

3 participants