Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle/node/db: Directly represent SQLite pragmas
Yorgos Saslis committed 2 months ago
commit 3cbd1fc216f3748f528c9e949a41d552141e2bd8
parent e9245b630d728672d2b3d6ff9265fa4f1a86f13a
3 files changed +18 -19
modified crates/radicle-node/src/runtime.rs
@@ -177,7 +177,7 @@ impl Runtime {
        log::info!(target: "node", "Opening node database..");
        let db = home
            .database_mut()?
-
            .journal_mode(node::db::JournalMode::default())?
+
            .journal_mode(node::db::JournalMode::WAL)?
            .init(
                &id,
                announcement.features,
modified crates/radicle/src/node/db.rs
@@ -49,17 +49,22 @@ pub enum Error {
    NoRows,
}

-
/// Database journal mode.
-
#[derive(Debug, Default, Copy, Clone, serde::Serialize, serde::Deserialize)]
-
#[serde(rename_all = "camelCase")]
+
/// Value for a `journal_mode` pragma statement.
+
/// For a description of all variants please refer to
+
/// <https://sqlite.org/pragma.html#pragma_journal_mode>.
+
/// Note that when SQLite documentation talks about "the application",
+
/// the application linked against this crate, e.g. Radicle Node, Radicle CLI,
+
/// and others, is meant.
+
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum JournalMode {
-
    /// "WAL" mode. Good for concurrent reads & writes, but keeps some extra files around.
-
    #[serde(rename = "wal")]
    #[default]
-
    WriteAheadLog,
-
    /// Default "rollback" mode. Certain writes may block reads.
-
    #[serde(alias = "rollback")]
-
    Rollback,
+
    DELETE,
+
    TRUNCATE,
+
    PERSIST,
+
    MEMORY,
+
    WAL,
+
    OFF,
}

/// A file-backed database storing information about the network.
@@ -117,14 +122,8 @@ impl Database {

    /// Set journal mode.
    pub fn journal_mode(self, mode: JournalMode) -> Result<Self, Error> {
-
        match mode {
-
            JournalMode::Rollback => {
-
                self.db.execute("PRAGMA journal_mode = DELETE;")?;
-
            }
-
            JournalMode::WriteAheadLog => {
-
                self.db.execute("PRAGMA journal_mode = WAL;")?;
-
            }
-
        }
+
        self.db
+
            .execute(format!("PRAGMA journal_mode = {mode:?};"))?;
        Ok(self)
    }

modified crates/radicle/src/profile.rs
@@ -253,7 +253,7 @@ impl Profile {
        home.policies_mut()?;
        home.notifications_mut()?;
        home.database_mut()?
-
            .journal_mode(node::db::JournalMode::default())?
+
            .journal_mode(node::db::JournalMode::WAL)?
            .init(
                &public_key,
                config.node.features(),