Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(notifications): extract row conversion helpers into store_rows

Steven Enamakelfbc7cef57435
diff --git a/crates/openhuman-core/src/desktop/notifications/store.rs b/crates/openhuman-core/src/desktop/notifications/store.rs
index 080e281991..2711f78373 100644
--- a/crates/openhuman-core/src/desktop/notifications/store.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store.rs
@@ -697,72 +697,8 @@ pub fn get_settings(config: &Config, provider: &str) -> Result<NotificationSetti
})
}
-// ─────────────────────────────────────────────────────────────────────────────
-// Row conversion helpers
-// ─────────────────────────────────────────────────────────────────────────────
-
-fn rows_to_notifications(mut rows: rusqlite::Rows<'_>) -> Result<Vec<IntegrationNotification>> {
- let mut out = Vec::new();
- while let Some(row) = rows
- .next()
- .context("[notifications::store] row iteration failed")?
- {
- out.push(row_to_notification(row)?);
- }
- Ok(out)
-}
-
-fn row_to_notification(row: &rusqlite::Row<'_>) -> Result<IntegrationNotification> {
- let raw_payload_str: String = row.get(5)?;
- let raw_payload: serde_json::Value = serde_json::from_str(&raw_payload_str)
- .unwrap_or(serde_json::Value::String(raw_payload_str));
-
- let status_str: String = row.get(9)?;
- let status = match status_str.as_str() {
- "read" => NotificationStatus::Read,
- "acted" => NotificationStatus::Acted,
- "dismissed" => NotificationStatus::Dismissed,
- _ => NotificationStatus::Unread,
- };
-
- let received_at_str: String = row.get(10)?;
- let received_at: DateTime<Utc> = received_at_str.parse().unwrap_or_else(|e| {
- tracing::warn!(
- raw = %received_at_str,
- error = %e,
- "[notifications::store] invalid received_at, using now"
- );
- Utc::now()
- });
-
- let scored_at_str: Option<String> = row.get(11)?;
- let scored_at: Option<DateTime<Utc>> = scored_at_str.and_then(|s| match s.parse() {
- Ok(t) => Some(t),
- Err(e) => {
- tracing::warn!(
- raw = %s,
- error = %e,
- "[notifications::store] invalid scored_at, treating as unscored"
- );
- None
- }
- });
-
- Ok(IntegrationNotification {
- id: row.get(0)?,
- provider: row.get(1)?,
- account_id: row.get(2)?,
- title: row.get(3)?,
- body: row.get(4)?,
- raw_payload,
- importance_score: row.get(6)?,
- triage_action: row.get(7)?,
- triage_reason: row.get(8)?,
- status,
- received_at,
- scored_at,
- })
-}
+mod store_rows;
+use store_rows::rows_to_notifications;
#[cfg(test)]
#[path = "store_tests.rs"]
diff --git a/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs b/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs
new file mode 100644
index 0000000000..f499eb35c7
--- /dev/null
+++ b/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs
@@ -0,0 +1,71 @@
+//! Row conversion for the SQLite notification store.
+
+use anyhow::{Context, Result};
+use chrono::{DateTime, Utc};
+
+use super::super::types::{IntegrationNotification, NotificationStatus};
+
+
+pub(super) fn rows_to_notifications(mut rows: rusqlite::Rows<'_>) -> Result<Vec<IntegrationNotification>> {
+ let mut out = Vec::new();
+ while let Some(row) = rows
+ .next()
+ .context("[notifications::store] row iteration failed")?
+ {
+ out.push(row_to_notification(row)?);
+ }
+ Ok(out)
+}
+
+fn row_to_notification(row: &rusqlite::Row<'_>) -> Result<IntegrationNotification> {
+ let raw_payload_str: String = row.get(5)?;
+ let raw_payload: serde_json::Value = serde_json::from_str(&raw_payload_str)
+ .unwrap_or(serde_json::Value::String(raw_payload_str));
+
+ let status_str: String = row.get(9)?;
+ let status = match status_str.as_str() {
+ "read" => NotificationStatus::Read,
+ "acted" => NotificationStatus::Acted,
+ "dismissed" => NotificationStatus::Dismissed,
+ _ => NotificationStatus::Unread,
+ };
+
+ let received_at_str: String = row.get(10)?;
+ let received_at: DateTime<Utc> = received_at_str.parse().unwrap_or_else(|e| {
+ tracing::warn!(
+ raw = %received_at_str,
+ error = %e,
+ "[notifications::store] invalid received_at, using now"
+ );
+ Utc::now()
+ });
+
+ let scored_at_str: Option<String> = row.get(11)?;
+ let scored_at: Option<DateTime<Utc>> = scored_at_str.and_then(|s| match s.parse() {
+ Ok(t) => Some(t),
+ Err(e) => {
+ tracing::warn!(
+ raw = %s,
+ error = %e,
+ "[notifications::store] invalid scored_at, treating as unscored"
+ );
+ None
+ }
+ });
+
+ Ok(IntegrationNotification {
+ id: row.get(0)?,
+ provider: row.get(1)?,
+ account_id: row.get(2)?,
+ title: row.get(3)?,
+ body: row.get(4)?,
+ raw_payload,
+ importance_score: row.get(6)?,
+ triage_action: row.get(7)?,
+ triage_reason: row.get(8)?,
+ status,
+ received_at,
+ scored_at,
+ })
+}
+
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
index b2bbb355be..d0b4460fa9 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
@@ -40,7 +40,7 @@ use super::types::{
NotificationStatus,
};
use crate::storage::documents::{compare_and_swap, text, Repo, CAS_ATTEMPTS};
-use crate::storage::{DocumentStore, DocumentStoreExt, ScopedStorage, StorageError};
+use crate::storage::{DocumentStore, DocumentStoreExt, StorageError};
const NOTIFICATIONS: &str = "integration_notifications";
const DEDUP: &str = "notification_dedup";
@@ -188,7 +188,7 @@ pub(super) struct Docs(Repo);
impl Docs {
#[cfg(test)]
- pub(super) fn over(scoped: &ScopedStorage) -> Self {
+ pub(super) fn over(scoped: &crate::storage::ScopedStorage) -> Self {
Self(Repo::over(scoped, DOMAIN, collections))
}
diff --git a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs b/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
index c6a34d5f1c..57c966b5c2 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
@@ -28,7 +28,7 @@ use super::types::{
};
use crate::integrations::composio::providers::NormalizedTask;
use crate::storage::documents::{compare_and_swap, text, Repo};
-use crate::storage::{DocumentStoreExt, ScopedStorage};
+use crate::storage::DocumentStoreExt;
const SOURCES: &str = "task_sources";
const INGESTED: &str = "ingested_tasks";
@@ -135,7 +135,7 @@ pub(super) struct Docs(Repo);
impl Docs {
#[cfg(test)]
- pub(super) fn over(scoped: &ScopedStorage) -> Self {
+ pub(super) fn over(scoped: &crate::storage::ScopedStorage) -> Self {
Self(Repo::over(scoped, DOMAIN, collections))
}
diff --git a/crates/openhuman-core/src/security/devices/store_documents.rs b/crates/openhuman-core/src/security/devices/store_documents.rs
index eae07023a7..3f58ba80aa 100644
--- a/crates/openhuman-core/src/security/devices/store_documents.rs
+++ b/crates/openhuman-core/src/security/devices/store_documents.rs
@@ -17,7 +17,7 @@ use tinystoragedrivers::{CollectionSpec, Filter, IndexSpec, Precondition, Query,
use crate::security::devices::types::PairedDevice;
use crate::storage::documents::{compare_and_swap, text, Repo};
-use crate::storage::{DocumentStoreExt, ScopedStorage};
+use crate::storage::DocumentStoreExt;
const DEVICES: &str = "paired_devices";
const DOMAIN: &str = "devices::store";
@@ -50,7 +50,7 @@ pub(super) struct Docs(Repo);
impl Docs {
#[cfg(test)]
- pub(super) fn over(scoped: &ScopedStorage) -> Self {
+ pub(super) fn over(scoped: &crate::storage::ScopedStorage) -> Self {
Self(Repo::over(scoped, DOMAIN, collections))
}