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};
pub trait FeedStorage {
type Error: snafu::Error + 'static;
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>;
fn operation_exists(&mut self, operation_id: &Oid) -> Result<bool, Self::Error>;
fn insert_batch(&mut self, entries: &[OperationEntry]) -> Result<(), Self::Error>;
fn get_stats(&mut self) -> Result<StorageStats, Self::Error>;
}
#[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;