pub struct DataStore { /* private fields */ }Expand description
Central data store for ccboard
Thread-safe access to all Claude Code data. Uses DashMap for sessions (high contention) and RwLock for stats/settings (low contention).
Implementations§
Source§impl DataStore
impl DataStore
Sourcepub fn new(
claude_home: PathBuf,
project_path: Option<PathBuf>,
config: DataStoreConfig,
) -> Self
pub fn new( claude_home: PathBuf, project_path: Option<PathBuf>, config: DataStoreConfig, ) -> Self
Create a new data store
Sourcepub fn with_defaults(
claude_home: PathBuf,
project_path: Option<PathBuf>,
) -> Self
pub fn with_defaults( claude_home: PathBuf, project_path: Option<PathBuf>, ) -> Self
Create with default configuration
Sourcepub fn degraded_state(&self) -> DegradedState
pub fn degraded_state(&self) -> DegradedState
Get current degraded state
Sourcepub async fn initial_load(&self) -> LoadReport
pub async fn initial_load(&self) -> LoadReport
Initial load of all data with LoadReport for graceful degradation
Sourcepub fn stats(&self) -> Option<StatsCache>
pub fn stats(&self) -> Option<StatsCache>
Get a clone of stats
Sourcepub fn context_window_stats(&self) -> ContextWindowStats
pub fn context_window_stats(&self) -> ContextWindowStats
Calculate context window saturation from current sessions
Sourcepub fn settings(&self) -> MergedConfig
pub fn settings(&self) -> MergedConfig
Get merged settings
Sourcepub fn mcp_config(&self) -> Option<McpConfig>
pub fn mcp_config(&self) -> Option<McpConfig>
Get MCP server configuration
Sourcepub fn invocation_stats(&self) -> InvocationStats
pub fn invocation_stats(&self) -> InvocationStats
Get invocation statistics
Sourcepub fn live_sessions(&self) -> Vec<LiveSession>
pub fn live_sessions(&self) -> Vec<LiveSession>
Get live Claude Code sessions (running processes)
Detects active Claude processes on the system and returns metadata. Returns empty vector if detection fails or no processes are running.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Get session count
Sourcepub fn get_session(&self, id: &str) -> Option<Arc<SessionMetadata>>
pub fn get_session(&self, id: &str) -> Option<Arc<SessionMetadata>>
Get session by ID
Returns Arc
Sourcepub fn analytics(&self) -> Option<AnalyticsData>
pub fn analytics(&self) -> Option<AnalyticsData>
Get analytics data for a period (cached)
Returns cached analytics if available, otherwise None.
Call compute_analytics() to compute and cache.
Sourcepub async fn compute_analytics(&self, period: Period)
pub async fn compute_analytics(&self, period: Period)
Compute and cache analytics data for a period
This is a CPU-intensive operation (trends, forecasting, patterns). For 1000+ sessions, this may take 100-300ms, so it’s offloaded to a blocking task.
Cache is invalidated on stats reload or session updates (EventBus pattern).
Sourcepub fn session_ids(&self) -> Vec<SessionId>
pub fn session_ids(&self) -> Vec<SessionId>
Get all session IDs
Sourcepub fn clear_session_content_cache(&self)
pub fn clear_session_content_cache(&self)
Clear session content cache (for memory optimization on F5)
Sourcepub fn sessions_by_project(&self) -> HashMap<String, Vec<Arc<SessionMetadata>>>
pub fn sessions_by_project(&self) -> HashMap<String, Vec<Arc<SessionMetadata>>>
Get sessions grouped by project
Returns Arc
Sourcepub fn all_sessions(&self) -> Vec<Arc<SessionMetadata>>
pub fn all_sessions(&self) -> Vec<Arc<SessionMetadata>>
Get all sessions (unsorted)
Returns Arc
Sourcepub fn recent_sessions(&self, limit: usize) -> Vec<Arc<SessionMetadata>>
pub fn recent_sessions(&self, limit: usize) -> Vec<Arc<SessionMetadata>>
Get recent sessions (sorted by last timestamp, newest first)
Returns Arc
Sourcepub fn top_sessions_by_tokens(&self, limit: usize) -> Vec<Arc<SessionMetadata>>
pub fn top_sessions_by_tokens(&self, limit: usize) -> Vec<Arc<SessionMetadata>>
Get top sessions by total tokens (sorted descending)
Returns Arc
Sourcepub fn top_models_by_tokens(&self) -> Vec<(String, u64)>
pub fn top_models_by_tokens(&self) -> Vec<(String, u64)>
Get top models by total tokens (aggregated, sorted descending) Returns (model_name, total_tokens) pairs
Sourcepub fn top_days_by_tokens(&self) -> Vec<(String, u64)>
pub fn top_days_by_tokens(&self) -> Vec<(String, u64)>
Get top days by total tokens (aggregated, sorted descending) Returns (date_string, total_tokens) pairs
Sourcepub fn projects_leaderboard(&self) -> Vec<ProjectLeaderboardEntry>
pub fn projects_leaderboard(&self) -> Vec<ProjectLeaderboardEntry>
Get project leaderboard with aggregated metrics
Returns all projects with session count, total tokens, total cost, and average session cost. Cost is calculated using accurate model-based pricing from the pricing module.
Sourcepub async fn reload_stats(&self)
pub async fn reload_stats(&self)
Reload stats (called on file change)
Sourcepub async fn reload_settings(&self)
pub async fn reload_settings(&self)
Reload settings from files (called when settings change)
Sourcepub async fn update_session(&self, path: &Path)
pub async fn update_session(&self, path: &Path)
Add or update a session (called when session file changes)
Sourcepub async fn compute_invocations(&self)
pub async fn compute_invocations(&self)
Compute invocation statistics from all sessions
This scans all session files to count agent/command/skill invocations. Should be called after initial load or when sessions are updated.
Sourcepub async fn compute_billing_blocks(&self)
pub async fn compute_billing_blocks(&self)
Compute billing blocks from all sessions
This scans all sessions with timestamps and aggregates usage into 5-hour billing blocks. Uses real model pricing based on token breakdown for accurate cost calculation.
Sourcepub fn billing_blocks(&self) -> RwLockReadGuard<'_, BillingBlockManager>
pub fn billing_blocks(&self) -> RwLockReadGuard<'_, BillingBlockManager>
Get billing blocks (read-only access)
Sourcepub fn usage_estimate(&self) -> UsageEstimate
pub fn usage_estimate(&self) -> UsageEstimate
Calculate usage estimate based on billing blocks and subscription plan