radicle-feed 0.5.3

A feed service for Radicle
Documentation
use std::fmt;

use radicle::cob::{ObjectId, TypeName};
use radicle::git::Oid;
use radicle::prelude::RepoId;

use crate::models::activity_feed::ActivityFeedOperation;
use crate::models::entry::{OperationEntry, TimelineEntry};

/// Trait for abstracting storage operations used by the rad-feed library.
/// Consumers can implement this trait to provide their own storage backend.
pub trait FeedStorage {
    type Error: snafu::Error + 'static;

    /// Get the last processed operation ID for a specific repository and COB (Collaborative Object)
    fn get_last_processed_operation(
        &mut self,
        rid: &RepoId,
        cob_id: &ObjectId,
        typename: &TypeName,
    ) -> Result<Option<String>, Self::Error>;

    fn get_operation_by_id(
        &mut self,
        id: &radicle::git::Oid,
    ) -> Result<ActivityFeedOperation, Self::Error>;

    fn resolve_rid(&mut self, rid: &RepoId) -> Result<Option<String>, Self::Error>;

    fn insert_timeline_entry(&mut self, entry: &TimelineEntry) -> Result<(), Self::Error>;

    /// Check if an operation already exists in storage (for duplicate prevention)
    fn operation_exists(&mut self, operation_id: &Oid) -> Result<bool, Self::Error>;

    /// Insert a batch of operations entries into storage
    fn insert_batch(&mut self, entries: &[OperationEntry]) -> Result<(), Self::Error>;

    /// Get statistics about stored data (optional, used for debugging/monitoring)
    fn get_stats(&mut self) -> Result<StorageStats, Self::Error>;
}

/// Statistics about the storage backend
#[derive(Debug, Default)]
pub struct StorageStats {
    pub total_operations: u64,
    pub operations_by_type: std::collections::HashMap<String, u64>,
    pub tracked_objects: u64,
}

impl fmt::Display for StorageStats {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        writeln!(f, "=== Storage Statistics ===")?;
        writeln!(f, "Total operations: {}", self.total_operations)?;

        for (kind, count) in &self.operations_by_type {
            writeln!(f, "{}: {}", kind, count)?;
        }

        writeln!(f, "Tracked objects: {}", self.tracked_objects)?;
        Ok(())
    }
}

pub mod postgres;