The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(task_sources): extract row mapping into store_rows module
Steven Enamakel8be09169ed84
diff --git a/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs b/crates/openhuman-core/src/desktop/notifications/store/store_rows.rsindex f499eb35c7..abafb02a1f 100644--- a/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs+++ b/crates/openhuman-core/src/desktop/notifications/store/store_rows.rs@@ -5,8 +5,9 @@ use chrono::{DateTime, Utc};use super::super::types::{IntegrationNotification, NotificationStatus};--pub(super) fn rows_to_notifications(mut rows: rusqlite::Rows<'_>) -> Result<Vec<IntegrationNotification>> {+pub(super) fn rows_to_notifications(+ mut rows: rusqlite::Rows<'_>,+) -> Result<Vec<IntegrationNotification>> {let mut out = Vec::new();while let Some(row) = rows.next()@@ -68,4 +69,3 @@ fn row_to_notification(row: &rusqlite::Row<'_>) -> Result<IntegrationNotificatioscored_at,})}-diff --git a/crates/openhuman-core/src/integrations/task_sources/store.rs b/crates/openhuman-core/src/integrations/task_sources/store.rsindex 7032cb32c3..f8131f31ad 100644--- a/crates/openhuman-core/src/integrations/task_sources/store.rs+++ b/crates/openhuman-core/src/integrations/task_sources/store.rs@@ -441,55 +441,8 @@ pub fn clear_all(config: &Config) -> Result<usize> {})}-const SELECT_SOURCE_COLUMNS: &str = "SELECT id, provider, connection_id, name, enabled, filter, \- interval_secs, target, max_tasks_per_fetch, created_at, last_fetch_at, last_status \- FROM task_sources";--fn map_source_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<TaskSource> {- let provider_raw: String = row.get(1)?;- let provider = ProviderSlug::parse(&provider_raw).map_err(sql_conv)?;-- let filter_raw: String = row.get(5)?;- let filter: FilterSpec = serde_json::from_str(&filter_raw)- .map_err(|e| sql_conv(format!("invalid filter json: {e}")))?;-- let target_raw: String = row.get(7)?;- let target: SourceTarget = serde_json::from_str(&target_raw)- .map_err(|e| sql_conv(format!("invalid target json: {e}")))?;-- let created_at_raw: String = row.get(9)?;- let last_fetch_raw: Option<String> = row.get(10)?;-- Ok(TaskSource {- id: row.get(0)?,- provider,- connection_id: row.get(2)?,- name: row.get(3)?,- enabled: row.get::<_, i64>(4)? != 0,- filter,- interval_secs: u64::try_from(row.get::<_, i64>(6)?)- .map_err(|_| sql_conv("invalid negative interval_secs in task_sources DB"))?,- target,- max_tasks_per_fetch: u32::try_from(row.get::<_, i64>(8)?)- .map_err(|_| sql_conv("invalid max_tasks_per_fetch in task_sources DB"))?,- created_at: parse_rfc3339(&created_at_raw).map_err(sql_conv)?,- last_fetch_at: match last_fetch_raw {- Some(raw) => Some(parse_rfc3339(&raw).map_err(sql_conv)?),- None => None,- },- last_status: row.get(11)?,- })-}--fn parse_rfc3339(raw: &str) -> Result<DateTime<Utc>> {- let parsed = DateTime::parse_from_rfc3339(raw)- .with_context(|| format!("Invalid RFC3339 timestamp in task_sources DB: {raw}"))?;- Ok(parsed.with_timezone(&Utc))-}--fn sql_conv<E: std::fmt::Display>(err: E) -> rusqlite::Error {- rusqlite::Error::ToSqlConversionFailure(anyhow::anyhow!("{err}").into())-}+mod store_rows;+use store_rows::{map_source_row, SELECT_SOURCE_COLUMNS};/// Tracks which task_sources database files have already had their schema DDL/// (the `CREATE TABLE`/`CREATE INDEX` batch plus the `add_column_if_missing`diff --git a/crates/openhuman-core/src/integrations/task_sources/store/store_rows.rs b/crates/openhuman-core/src/integrations/task_sources/store/store_rows.rsnew file mode 100644index 0000000000..a6f43d9760--- /dev/null+++ b/crates/openhuman-core/src/integrations/task_sources/store/store_rows.rs@@ -0,0 +1,57 @@+//! Row conversion for the SQLite task-source store.++use anyhow::{Context, Result};+use chrono::{DateTime, Utc};++use super::super::types::{FilterSpec, ProviderSlug, SourceTarget, TaskSource};++pub(super) const SELECT_SOURCE_COLUMNS: &str =+ "SELECT id, provider, connection_id, name, enabled, filter, \+ interval_secs, target, max_tasks_per_fetch, created_at, last_fetch_at, last_status \+ FROM task_sources";++pub(super) fn map_source_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<TaskSource> {+ let provider_raw: String = row.get(1)?;+ let provider = ProviderSlug::parse(&provider_raw).map_err(sql_conv)?;++ let filter_raw: String = row.get(5)?;+ let filter: FilterSpec = serde_json::from_str(&filter_raw)+ .map_err(|e| sql_conv(format!("invalid filter json: {e}")))?;++ let target_raw: String = row.get(7)?;+ let target: SourceTarget = serde_json::from_str(&target_raw)+ .map_err(|e| sql_conv(format!("invalid target json: {e}")))?;++ let created_at_raw: String = row.get(9)?;+ let last_fetch_raw: Option<String> = row.get(10)?;++ Ok(TaskSource {+ id: row.get(0)?,+ provider,+ connection_id: row.get(2)?,+ name: row.get(3)?,+ enabled: row.get::<_, i64>(4)? != 0,+ filter,+ interval_secs: u64::try_from(row.get::<_, i64>(6)?)+ .map_err(|_| sql_conv("invalid negative interval_secs in task_sources DB"))?,+ target,+ max_tasks_per_fetch: u32::try_from(row.get::<_, i64>(8)?)+ .map_err(|_| sql_conv("invalid max_tasks_per_fetch in task_sources DB"))?,+ created_at: parse_rfc3339(&created_at_raw).map_err(sql_conv)?,+ last_fetch_at: match last_fetch_raw {+ Some(raw) => Some(parse_rfc3339(&raw).map_err(sql_conv)?),+ None => None,+ },+ last_status: row.get(11)?,+ })+}++fn parse_rfc3339(raw: &str) -> Result<DateTime<Utc>> {+ let parsed = DateTime::parse_from_rfc3339(raw)+ .with_context(|| format!("Invalid RFC3339 timestamp in task_sources DB: {raw}"))?;+ Ok(parsed.with_timezone(&Utc))+}++fn sql_conv<E: std::fmt::Display>(err: E) -> rusqlite::Error {+ rusqlite::Error::ToSqlConversionFailure(anyhow::anyhow!("{err}").into())+}