Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions backend/src/modem_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,25 @@ fn sms_storage_cache_entry_for_identity(
/// 缓存的存储条目若无 total(此前抓取失败写入的 "empty" 占位),视为不完整。
/// 仅用于后台刷新流程内部的重试判断;不影响 sim_details_cache_missing 的
/// 自动触发语义(空占位在 ICCID 变化前不重复触发探测)。
fn sms_storage_cache_incomplete(db: &Database, identity: &SimIdentity) -> bool {
pub fn sms_storage_cache_incomplete(db: &Database, identity: &SimIdentity) -> bool {
sms_storage_cache_entry_for_identity(db, identity)
.map(|entry| entry.sms_total.is_none())
.unwrap_or(true)
}

/// 检查缓存是否超过 60 分钟未刷新,用于后台自动重新查询 CPMS
fn sms_storage_cache_stale(db: &Database, identity: &SimIdentity) -> bool {
let Some(entry) = sms_storage_cache_entry_for_identity(db, identity) else {
return true;
};
let Ok(updated) = chrono::DateTime::parse_from_rfc3339(&entry.updated_at) else {
return true;
};
let elapsed = chrono::Utc::now().signed_duration_since(updated);
elapsed.num_minutes() >= 60
}


fn cache_sms_storage_for_identity(
db: &Database,
identity: &SimIdentity,
Expand Down Expand Up @@ -1879,7 +1892,7 @@ async fn refresh_sim_details_background_inner(conn: &Connection, db: &Database,
cache_smsc_for_identity(db, &identity, &sms_center, source);
}

if force || sms_storage_cache_incomplete(db, &identity) {
if force || sms_storage_cache_incomplete(db, &identity) || sms_storage_cache_stale(db, &identity) {
let mut storage = None;
if let Some(path) = modem_path.as_deref() {
if let Ok(output) = send_at_via_modem_command(conn, path, "AT+CPMS?").await {
Expand Down