From 7d0b36450d3da7991bfde832a827a0cce4ad2393 Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Sat, 1 Aug 2026 01:23:36 +0200 Subject: [PATCH] [fix](trx-server): persist all decoder histories --- src/trx-server/src/audio.rs | 19 ++++- src/trx-server/src/history_store.rs | 118 +++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 2 deletions(-) diff --git a/src/trx-server/src/audio.rs b/src/trx-server/src/audio.rs index 52cdfbf2..082549a1 100644 --- a/src/trx-server/src/audio.rs +++ b/src/trx-server/src/audio.rs @@ -378,7 +378,7 @@ pub struct DecoderHistories { pub lrpt: Mutex>, pub wefax: Mutex>, /// Approximate total entry count across all decoders, maintained - /// atomically so `estimated_total_count()` avoids 9 lock acquisitions. + /// atomically so `estimated_total_count()` avoids 11 lock acquisitions. total_count: AtomicUsize, } @@ -845,6 +845,23 @@ impl DecoderHistories { pub fn estimated_total_count(&self) -> usize { self.total_count.load(Ordering::Relaxed) } + + /// Rebuild the aggregate count after bulk restoration bypasses the normal + /// record methods. + pub(crate) fn recalculate_total_count(&self) { + let total = lock_or_recover(&self.ais, "ais_history").len() + + lock_or_recover(&self.vdes, "vdes_history").len() + + lock_or_recover(&self.aprs, "aprs_history").len() + + lock_or_recover(&self.hf_aprs, "hf_aprs_history").len() + + lock_or_recover(&self.cw, "cw_history").len() + + lock_or_recover(&self.ft8, "ft8_history").len() + + lock_or_recover(&self.ft4, "ft4_history").len() + + lock_or_recover(&self.ft2, "ft2_history").len() + + lock_or_recover(&self.wspr, "wspr_history").len() + + lock_or_recover(&self.lrpt, "lrpt_history").len() + + lock_or_recover(&self.wefax, "wefax_history").len(); + self.total_count.store(total, Ordering::Relaxed); + } } /// Spawn the audio capture thread. diff --git a/src/trx-server/src/history_store.rs b/src/trx-server/src/history_store.rs index e5c5abdf..462f92fa 100644 --- a/src/trx-server/src/history_store.rs +++ b/src/trx-server/src/history_store.rs @@ -19,7 +19,7 @@ use pickledb::{PickleDb, PickleDbDumpPolicy, SerializationMethod}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use trx_core::decode::{ - AisMessage, AprsPacket, CwEvent, Ft8Message, VdesMessage, WefaxMessage, WsprMessage, + AisMessage, AprsPacket, CwEvent, Ft8Message, LrptImage, VdesMessage, WefaxMessage, WsprMessage, }; use crate::audio::DecoderHistories; @@ -118,6 +118,11 @@ pub fn load_all(db: &PickleDb, rig_id: &str, histories: &Arc) h.push_back(e); } } + if let Ok(mut h) = histories.hf_aprs.lock() { + for e in load_key::(db, &k("hf_aprs")) { + h.push_back(e); + } + } if let Ok(mut h) = histories.cw.lock() { for e in load_key::(db, &k("cw")) { h.push_back(e); @@ -128,16 +133,32 @@ pub fn load_all(db: &PickleDb, rig_id: &str, histories: &Arc) h.push_back(e); } } + if let Ok(mut h) = histories.ft4.lock() { + for e in load_key::(db, &k("ft4")) { + h.push_back(e); + } + } + if let Ok(mut h) = histories.ft2.lock() { + for e in load_key::(db, &k("ft2")) { + h.push_back(e); + } + } if let Ok(mut h) = histories.wspr.lock() { for e in load_key::(db, &k("wspr")) { h.push_back(e); } } + if let Ok(mut h) = histories.lrpt.lock() { + for e in load_key::(db, &k("lrpt")) { + h.push_back(e); + } + } if let Ok(mut h) = histories.wefax.lock() { for e in load_key::(db, &k("wefax")) { h.push_back(e); } } + histories.recalculate_total_count(); } /// Flush `histories` to the database under `rig_id`-prefixed keys and sync. @@ -162,6 +183,11 @@ pub fn flush_all(db: &mut PickleDb, rig_id: &str, histories: &Arc