Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
protocol: defer refs db populate to idle
Quaylyn Rimer committed 3 months ago
commit b25bb21b1438ebf205f58f689fad05ac6984c2c4
parent e25268eea2014236c2ab25163fa3ba9e0217ed9e
1 file changed +14 -4
modified crates/radicle-protocol/src/service.rs
@@ -467,6 +467,8 @@ pub struct Service<D, S, G> {
    listening: Vec<net::SocketAddr>,
    /// Latest metrics for all nodes connected to since the last start.
    metrics: Metrics,
+
    /// Whether refs DB population is pending.
+
    refs_populate_pending: bool,
}

impl<D, S, G> Service<D, S, G> {
@@ -535,6 +537,7 @@ where
            emitter,
            listening: vec![],
            metrics: Metrics::default(),
+
            refs_populate_pending: false,
        }
    }

@@ -669,10 +672,8 @@ where
        // 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) {
-
                    warn!(target: "service", "Failed to populate refs database: {e}");
-
                }
+
                info!(target: "service", "Empty refs database, deferring populate from storage..");
+
                self.refs_populate_pending = true;
            }
            Ok(n) => debug!(target: "service", "Refs database has {n} cached references"),
            Err(e) => {
@@ -794,6 +795,15 @@ where
        if now - self.last_idle >= IDLE_INTERVAL {
            trace!(target: "service", "Running 'idle' task...");

+
            if self.refs_populate_pending {
+
                info!(target: "service", "Populating refs database from storage..");
+
                self.refs_populate_pending = false;
+
                if let Err(e) = self.db.refs_mut().populate(&self.storage) {
+
                    warn!(target: "service", "Failed to populate refs database: {e}");
+
                    self.refs_populate_pending = true;
+
                }
+
            }
+

            self.keep_alive(&now);
            self.disconnect_unresponsive_peers(&now);
            self.idle_connections();