8103dae2be
api::rows now also loads settlements, audit entries and the epoch (sync::rows is gone; audit enums parse through rows::token) and owns the expense, split, settlement and allocation inserts that sync push, recurring generation and the importer each had their own copy of (rows::Origin carries the server-owned columns). accounts::insert_account and replace_shares are shared with the importer. Recurring generation moves the per-period expense into create_period_expense. No SQL, wire or log change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
//! The sync protocol v1 (SPEC §14.4): pull ([`pull`]), push processing ([`push`]) with the validation of step 8
|
|
//! ([`check`]), and the daily pruning of `sync_mutations` ([`prune_mutations`]). The HTTP handlers are in
|
|
//! `api/sync.rs`.
|
|
|
|
pub mod check;
|
|
pub mod pull;
|
|
pub mod push;
|
|
|
|
use chrono::{DateTime, Duration, Utc};
|
|
|
|
use crate::db::{self, Db};
|
|
use crate::error::AppError;
|
|
use crate::time::format_ts;
|
|
|
|
/// How long `sync_mutations` rows are kept (SPEC §14.4.9, D-021).
|
|
pub const MUTATION_RETENTION: Duration = Duration::days(90);
|
|
|
|
/// Deletes the `sync_mutations` rows whose `received_at` is older than 90 days before `now` (SPEC §14.1). Returns
|
|
/// the number of rows deleted. Timestamps are in the fixed RFC 3339 form, so text order is time order.
|
|
pub async fn prune_mutations(db: &Db, now: DateTime<Utc>) -> Result<u64, AppError> {
|
|
let cutoff = format_ts(now - MUTATION_RETENTION);
|
|
let mut tx = db::begin_immediate(db).await?;
|
|
let deleted = sqlx::query("DELETE FROM sync_mutations WHERE received_at < ?")
|
|
.bind(cutoff)
|
|
.execute(&mut *tx)
|
|
.await?
|
|
.rows_affected();
|
|
tx.commit().await?;
|
|
Ok(deleted)
|
|
}
|