//! 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) -> Result { 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) }