From 199563550dd41c3dfb703bd3747604a8a03cdbc5 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 11 Jun 2026 14:20:49 +0200 Subject: chore: Remove all `pub`s They will not be marked by rustc/cargo as unused, and as atuin doesn't expose an API all of them _should_ be `pub(crate)` --- crates/turtle/src/atuin_daemon/search/index.rs | 56 +++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'crates/turtle/src/atuin_daemon/search/index.rs') diff --git a/crates/turtle/src/atuin_daemon/search/index.rs b/crates/turtle/src/atuin_daemon/search/index.rs index df627e1b..446d7992 100644 --- a/crates/turtle/src/atuin_daemon/search/index.rs +++ b/crates/turtle/src/atuin_daemon/search/index.rs @@ -38,16 +38,16 @@ fn format_uuid_bytes(bytes: &[u8; 16]) -> String { /// Pre-computed frecency data for O(1) lookup. #[derive(Debug, Clone, Default)] -pub struct FrecencyData { +pub(crate) struct FrecencyData { /// Total number of times this command was used. - pub count: u32, + pub(crate) count: u32, /// Most recent usage timestamp (unix seconds). - pub last_used: i64, + pub(crate) last_used: i64, } impl FrecencyData { /// Record a new usage of this command. - pub fn record_use(&mut self, timestamp: i64) { + pub(crate) fn record_use(&mut self, timestamp: i64) { self.count += 1; if timestamp > self.last_used { self.last_used = timestamp; @@ -66,7 +66,7 @@ impl FrecencyData { /// A multiplier of 0.0 disables that component, 1.0 is unchanged, 2.0 doubles weight. /// Values like 0.5 reduce weight by half, 1.5 increases by 50%, etc. #[instrument(level = tracing::Level::TRACE, name = "index_frecency_compute")] - pub fn compute(&self, now: i64, recency_mul: f64, frequency_mul: f64) -> u32 { + pub(crate) fn compute(&self, now: i64, recency_mul: f64, frequency_mul: f64) -> u32 { if self.count == 0 { return 0; } @@ -99,13 +99,13 @@ impl FrecencyData { } /// Data for a unique command. -pub struct CommandData { +pub(crate) struct CommandData { /// History ID of the most recent invocation (16-byte UUID). most_recent_id: [u8; 16], /// Timestamp of the most recent invocation. most_recent_timestamp: i64, /// Pre-computed global frecency. - pub global_frecency: FrecencyData, + pub(crate) global_frecency: FrecencyData, // Pre-computed indexes for O(1) filter lookups // Using HashSet instead of DashSet since CommandData lives inside DashMap (already synchronized) @@ -120,7 +120,7 @@ pub struct CommandData { impl CommandData { /// Create a new CommandData from a history entry. /// Returns None if the history entry has invalid UUIDs. - pub fn new(history: &History, interner: &ThreadedRodeo) -> Option { + pub(crate) fn new(history: &History, interner: &ThreadedRodeo) -> Option { let history_id = parse_uuid_bytes(&history.id.0)?; let session = parse_uuid_bytes(&history.session)?; let timestamp = history.timestamp.unix_timestamp(); @@ -152,7 +152,7 @@ impl CommandData { /// Add an invocation from a history entry. /// Returns false if the history entry has invalid UUIDs. - pub fn add_invocation(&mut self, history: &History, interner: &ThreadedRodeo) -> bool { + pub(crate) fn add_invocation(&mut self, history: &History, interner: &ThreadedRodeo) -> bool { let Some(history_id) = parse_uuid_bytes(&history.id.0) else { return false; }; @@ -181,13 +181,13 @@ impl CommandData { } /// Get the most recent history ID for this command. - pub fn most_recent_id(&self) -> String { + pub(crate) fn most_recent_id(&self) -> String { format_uuid_bytes(&self.most_recent_id) } /// Check if any invocation matches a directory filter (exact match). /// O(1) lookup using pre-computed index. - pub fn has_invocation_in_dir(&self, dir: &str, interner: &ThreadedRodeo) -> bool { + pub(crate) fn has_invocation_in_dir(&self, dir: &str, interner: &ThreadedRodeo) -> bool { interner .get(dir) .is_some_and(|spur| self.directories.contains(&spur)) @@ -195,7 +195,7 @@ impl CommandData { /// Check if any invocation matches a directory prefix (workspace/git root). /// O(n) where n = number of unique directories for this command. - pub fn has_invocation_in_workspace(&self, prefix: &str, interner: &ThreadedRodeo) -> bool { + pub(crate) fn has_invocation_in_workspace(&self, prefix: &str, interner: &ThreadedRodeo) -> bool { self.directories .iter() .any(|&spur| interner.resolve(&spur).starts_with(prefix)) @@ -203,7 +203,7 @@ impl CommandData { /// Check if any invocation matches a hostname. /// O(1) lookup using pre-computed index. - pub fn has_invocation_on_host(&self, hostname: &str, interner: &ThreadedRodeo) -> bool { + pub(crate) fn has_invocation_on_host(&self, hostname: &str, interner: &ThreadedRodeo) -> bool { interner .get(hostname) .is_some_and(|spur| self.hosts.contains(&spur)) @@ -211,14 +211,14 @@ impl CommandData { /// Check if any invocation matches a session. /// O(1) lookup using pre-computed index. - pub fn has_invocation_in_session(&self, session: &str) -> bool { + pub(crate) fn has_invocation_in_session(&self, session: &str) -> bool { parse_uuid_bytes(session).is_some_and(|bytes| self.sessions.contains(&bytes)) } } /// Filter mode for search queries. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum IndexFilterMode { +pub(crate) enum IndexFilterMode { /// No filtering - search all commands. Global, /// Filter to commands run in a specific directory. @@ -233,11 +233,11 @@ pub enum IndexFilterMode { /// Context for search queries. #[derive(Debug, Clone, Default)] -pub struct QueryContext { - pub cwd: Option, - pub git_root: Option, - pub hostname: Option, - pub session_id: Option, +pub(crate) struct QueryContext { + pub(crate) cwd: Option, + pub(crate) git_root: Option, + pub(crate) hostname: Option, + pub(crate) session_id: Option, } /// Shareable frecency map: command -> frecency score. @@ -252,7 +252,7 @@ type FrecencyMap = Arc, u32>>; /// Global frecency is precomputed by a background task and used for scoring. /// If frecency data is not available, search still works but without frecency ranking; /// although this should never happen due to precomputing the frecency map. -pub struct SearchIndex { +pub(crate) struct SearchIndex { /// Map from command text to command data. /// Using DashMap for concurrent read/write access, wrapped in Arc for sharing with scorer. /// Keys are Arc to enable zero-copy sharing with frecency_map. @@ -269,7 +269,7 @@ pub struct SearchIndex { impl SearchIndex { /// Create a new empty search index. - pub fn new() -> Self { + pub(crate) fn new() -> Self { let nucleo_config = atuin_nucleo::Config::DEFAULT; // Single column for command text let nucleo = Nucleo::::new(nucleo_config, Arc::new(|| {}), None, 1); @@ -288,7 +288,7 @@ impl SearchIndex { /// /// If the command already exists, updates its invocation data. /// If it's a new command, adds it to both the map and Nucleo. - pub fn add_history(&self, history: &History) { + pub(crate) fn add_history(&self, history: &History) { if is_known_agent(&history.author) { return; } @@ -315,19 +315,19 @@ impl SearchIndex { } /// Add multiple history entries to the index. - pub fn add_histories(&self, histories: &[History]) { + pub(crate) fn add_histories(&self, histories: &[History]) { for history in histories { self.add_history(history); } } /// Get the number of unique commands in the index. - pub fn command_count(&self) -> usize { + pub(crate) fn command_count(&self) -> usize { self.commands.len() } /// Get the number of items in Nucleo (should match command_count). - pub async fn nucleo_item_count(&self) -> u32 { + pub(crate) async fn nucleo_item_count(&self) -> u32 { self.nucleo.read().await.snapshot().item_count() } @@ -336,7 +336,7 @@ impl SearchIndex { /// Returns a list of history IDs (most recent invocation per command). /// Uses precomputed global frecency for scoring if available. #[instrument(skip_all, level = tracing::Level::TRACE, name = "index_search", fields(query = %query))] - pub async fn search( + pub(crate) async fn search( &self, query: &str, filter_mode: IndexFilterMode, @@ -398,7 +398,7 @@ impl SearchIndex { /// - `frequency_score_multiplier`: Weight for frequency component /// - `frecency_score_multiplier`: Overall multiplier for final score #[instrument(skip_all, level = tracing::Level::DEBUG, name = "rebuild_frecency")] - pub async fn rebuild_frecency(&self, search_settings: &Search) { + pub(crate) async fn rebuild_frecency(&self, search_settings: &Search) { let now = OffsetDateTime::now_utc().unix_timestamp(); let mut frecency_map: HashMap, u32> = HashMap::new(); -- cgit v1.3.1