diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index fad9cfa54..c7069ab7c 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -555,6 +555,19 @@ where let nid = self.node_id(); self.started_at = Some(time); + // Populate refs database. This is only useful as part of the upgrade process for nodes + // that have been online since before the refs database was created. + match self.db.refs().count() { + Ok(0) => { + info!(target: "service", "Empty refs database, populating from storage.."); + if let Err(e) = self.db.refs_mut().populate(&self.storage) { + error!(target: "service", "Failed to populate refs database: {e}"); + } + } + Ok(n) => debug!(target: "service", "Refs database has {n} cached references"), + Err(e) => error!(target: "service", "Error checking refs database: {e}"), + } + // Ensure that our local node is in our address database. self.db .addresses_mut() diff --git a/scripts/clear-refs-db.sh b/scripts/clear-refs-db.sh new file mode 100755 index 000000000..ff70af01b --- /dev/null +++ b/scripts/clear-refs-db.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +DB="$(rad path)/node/node.db" + +if command -v sqlite3 >/dev/null 2>&1; then + if [ -f "$DB" ]; then + echo -n "Clearing 'refs' table from $DB.. " + sqlite3 $DB "DELETE FROM refs;" + echo "done." + else + echo "fatal: database file does not exist" + exit 1 + fi +else + echo "fatal: sqlite3 is not installed" + exit 1 +fi