feedsignal-db's Db impl had grown into one 250-line block mixing feed subscriptions, article storage/scoring, reading-event logging, and topic-affinity persistence in a single file. Split each domain's methods into its own module (mirroring the earlier web crate SRP split), keeping lib.rs to just the Db struct and connection setup. Pure move — no behavior or public API changes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QmwX8eafbMstJvt8XPSqft
30 lines
1.1 KiB
Rust
30 lines
1.1 KiB
Rust
use crate::schema;
|
|
use crate::Db;
|
|
use anyhow::Result;
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
use feedsignal_core::{ReadingEvent, ReadingOutcome};
|
|
|
|
impl Db {
|
|
pub async fn record_event(&self, event: &ReadingEvent) -> Result<()> {
|
|
use schema::reading_events::dsl;
|
|
let mut conn = self.pool.get().await?;
|
|
let (outcome, dwell) = match &event.outcome {
|
|
ReadingOutcome::Impression => ("impression", None),
|
|
ReadingOutcome::Opened { dwell_seconds } => ("opened", dwell_seconds.map(|v| v as i32)),
|
|
ReadingOutcome::Starred => ("starred", None),
|
|
ReadingOutcome::Dismissed => ("dismissed", None),
|
|
};
|
|
diesel::insert_into(dsl::reading_events)
|
|
.values((
|
|
dsl::id.eq(event.id.to_string()),
|
|
dsl::article_id.eq(event.article_id.to_string()),
|
|
dsl::occurred_at.eq(event.occurred_at.to_rfc3339()),
|
|
dsl::outcome.eq(outcome),
|
|
dsl::dwell_seconds.eq(dwell),
|
|
))
|
|
.execute(&mut conn)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
}
|