From 1d1b9c3d49284be3e032f3682e2b12c27912b45e Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 9 Aug 2024 10:54:04 +0200 Subject: [PATCH] radicle: Don't use transactions in cache The `transaction` method was being used for single queries. This was unnecessary. --- radicle/src/cob/issue/cache.rs | 41 +++++++++++++++------------------- radicle/src/cob/patch/cache.rs | 41 +++++++++++++++------------------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/radicle/src/cob/issue/cache.rs b/radicle/src/cob/issue/cache.rs index 8b0eb7fb..80a3122b 100644 --- a/radicle/src/cob/issue/cache.rs +++ b/radicle/src/cob/issue/cache.rs @@ -11,7 +11,6 @@ use crate::cob::store; use crate::cob::{Embed, Label, ObjectId, TypeName}; use crate::crypto::Signer; use crate::prelude::{Did, RepoId}; -use crate::sql::transaction; use crate::storage::{HasRepoId, ReadRepository, RepositoryError, SignRepository, WriteRepository}; use super::{Issue, IssueCounts, IssueId, IssueMut, State}; @@ -295,21 +294,19 @@ impl Update for StoreWriter { id: &ObjectId, object: &Issue, ) -> Result { - transaction::<_, UpdateError>(&self.db, move |db| { - let mut stmt = db.prepare( - "INSERT INTO issues (id, repo, issue) - VALUES (?1, ?2, ?3) - ON CONFLICT DO UPDATE - SET issue = (?3)", - )?; + let mut stmt = self.db.prepare( + "INSERT INTO issues (id, repo, issue) + VALUES (?1, ?2, ?3) + ON CONFLICT DO UPDATE + SET issue = (?3)", + )?; - stmt.bind((1, sql::Value::String(id.to_string())))?; - stmt.bind((2, rid))?; - stmt.bind((3, sql::Value::String(serde_json::to_string(&object)?)))?; - stmt.next()?; + stmt.bind((1, sql::Value::String(id.to_string())))?; + stmt.bind((2, rid))?; + stmt.bind((3, sql::Value::String(serde_json::to_string(&object)?)))?; + stmt.next()?; - Ok(db.change_count() > 0) - }) + Ok(self.db.change_count() > 0) } } @@ -318,17 +315,15 @@ impl Remove for StoreWriter { type RemoveError = sql::Error; fn remove(&mut self, id: &ObjectId) -> Result { - transaction::<_, sql::Error>(&self.db, move |db| { - let mut stmt = db.prepare( - "DELETE FROM issues - WHERE id = ?1", - )?; + let mut stmt = self.db.prepare( + "DELETE FROM issues + WHERE id = ?1", + )?; - stmt.bind((1, sql::Value::String(id.to_string())))?; - stmt.next()?; + stmt.bind((1, sql::Value::String(id.to_string())))?; + stmt.next()?; - Ok(db.change_count() > 0) - }) + Ok(self.db.change_count() > 0) } fn remove_all(&mut self, rid: &RepoId) -> Result { diff --git a/radicle/src/cob/patch/cache.rs b/radicle/src/cob/patch/cache.rs index 72ef3700..17736836 100644 --- a/radicle/src/cob/patch/cache.rs +++ b/radicle/src/cob/patch/cache.rs @@ -12,7 +12,6 @@ use crate::cob::{Label, ObjectId, TypeName}; use crate::crypto::Signer; use crate::git; use crate::prelude::RepoId; -use crate::sql::transaction; use crate::storage::{HasRepoId, ReadRepository, RepositoryError, SignRepository, WriteRepository}; use super::{ @@ -362,21 +361,19 @@ impl Update for StoreWriter { id: &ObjectId, object: &Patch, ) -> Result { - transaction::<_, UpdateError>(&self.db, move |db| { - let mut stmt = db.prepare( - "INSERT INTO patches (id, repo, patch) - VALUES (?1, ?2, ?3) - ON CONFLICT DO UPDATE - SET patch = (?3)", - )?; + let mut stmt = self.db.prepare( + "INSERT INTO patches (id, repo, patch) + VALUES (?1, ?2, ?3) + ON CONFLICT DO UPDATE + SET patch = (?3)", + )?; - stmt.bind((1, sql::Value::String(id.to_string())))?; - stmt.bind((2, rid))?; - stmt.bind((3, sql::Value::String(serde_json::to_string(&object)?)))?; - stmt.next()?; + stmt.bind((1, sql::Value::String(id.to_string())))?; + stmt.bind((2, rid))?; + stmt.bind((3, sql::Value::String(serde_json::to_string(&object)?)))?; + stmt.next()?; - Ok(db.change_count() > 0) - }) + Ok(self.db.change_count() > 0) } } @@ -385,17 +382,15 @@ impl Remove for StoreWriter { type RemoveError = sql::Error; fn remove(&mut self, id: &ObjectId) -> Result { - transaction::<_, sql::Error>(&self.db, move |db| { - let mut stmt = db.prepare( - "DELETE FROM patches - WHERE id = ?1", - )?; + let mut stmt = self.db.prepare( + "DELETE FROM patches + WHERE id = ?1", + )?; - stmt.bind((1, sql::Value::String(id.to_string())))?; - stmt.next()?; + stmt.bind((1, sql::Value::String(id.to_string())))?; + stmt.next()?; - Ok(db.change_count() > 0) - }) + Ok(self.db.change_count() > 0) } fn remove_all(&mut self, rid: &RepoId) -> Result {