Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Don't use transactions in cache
cloudhead committed 1 year ago
commit 1d1b9c3d49284be3e032f3682e2b12c27912b45e
parent 9db69a40a62442a1c6959cdda553fe7a57105709
2 files changed +40 -50
modified 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<Issue> for StoreWriter {
        id: &ObjectId,
        object: &Issue,
    ) -> Result<Self::Out, Self::UpdateError> {
-
        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)",
-
            )?;
-

-
            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)
-
        })
+
        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()?;
+

+
        Ok(self.db.change_count() > 0)
    }
}

@@ -318,17 +315,15 @@ impl Remove<Issue> for StoreWriter {
    type RemoveError = sql::Error;

    fn remove(&mut self, id: &ObjectId) -> Result<Self::Out, Self::RemoveError> {
-
        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<Self::Out, Self::RemoveError> {
modified 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<Patch> for StoreWriter {
        id: &ObjectId,
        object: &Patch,
    ) -> Result<Self::Out, Self::UpdateError> {
-
        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)",
-
            )?;
-

-
            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)
-
        })
+
        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()?;
+

+
        Ok(self.db.change_count() > 0)
    }
}

@@ -385,17 +382,15 @@ impl Remove<Patch> for StoreWriter {
    type RemoveError = sql::Error;

    fn remove(&mut self, id: &ObjectId) -> Result<Self::Out, Self::RemoveError> {
-
        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<Self::Out, Self::RemoveError> {