diff --git a/parakeet/src/common/cache/mod.rs b/parakeet/src/common/cache/mod.rs deleted file mode 100644 index aca8306c..00000000 --- a/parakeet/src/common/cache/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Cache infrastructure modules - -pub mod id_helpers; -pub mod listener; -pub mod timeline; - -// Re-export commonly used items -pub use id_helpers::{get_actor_id_or_fetch, get_actor_dids_or_fetch, get_actor_ids_or_fetch}; -pub use listener::spawn_cache_listener; -pub use timeline::{AuthorFeedCache, TimelineCache}; \ No newline at end of file diff --git a/parakeet/src/common/cache/id_helpers.rs b/parakeet/src/common/cache_id_helpers.rs similarity index 100% rename from parakeet/src/common/cache/id_helpers.rs rename to parakeet/src/common/cache_id_helpers.rs diff --git a/parakeet/src/common/cache/listener.rs b/parakeet/src/common/cache_listener.rs similarity index 100% rename from parakeet/src/common/cache/listener.rs rename to parakeet/src/common/cache_listener.rs diff --git a/parakeet/src/common/cache/timeline.rs b/parakeet/src/common/cache_timeline.rs similarity index 100% rename from parakeet/src/common/cache/timeline.rs rename to parakeet/src/common/cache_timeline.rs diff --git a/parakeet/src/common/mod.rs b/parakeet/src/common/mod.rs deleted file mode 100644 index 15e13efc..00000000 --- a/parakeet/src/common/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! Common infrastructure and utilities shared across the application - -pub mod auth; -pub mod cache; -pub mod errors; -pub mod helpers; -pub mod rate_limiting; - -// Re-export commonly used items -pub use auth::{AtpAcceptLabelers, AtpAuth, JwtVerifier}; -pub use errors::{Error, XrpcResult}; -pub use rate_limiting::{rate_limit_middleware, RateLimiter}; \ No newline at end of file diff --git a/parakeet/src/entities/mod.rs b/parakeet/src/entities/mod.rs deleted file mode 100644 index e9680f07..00000000 --- a/parakeet/src/entities/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub mod actor_ext; -pub mod post; -pub mod post_converter; -pub mod post_ext; -pub mod profile; -pub mod profile_converter; -pub mod feedgen; -pub mod list; -pub mod starterpack; -pub mod notification; - -#[cfg(test)] -mod profile_tests; -#[cfg(test)] -mod post_tests; -#[cfg(test)] -mod notification_tests; -#[cfg(test)] -mod list_tests; -#[cfg(test)] -mod feedgen_tests; -#[cfg(test)] -mod starterpack_tests; - -pub use actor_ext::ActorExt; -pub use post::{PostEntity, PostConfig, PostData, PostCacheStats}; -pub use post_ext::{PostExt, PostDataExt}; -pub use profile::{ProfileEntity, ProfileConfig, ProfileData, CacheStats}; -pub use feedgen::{FeedGeneratorEntity, FeedGeneratorConfig}; -pub use list::{ListEntity, ListConfig}; -pub use starterpack::{StarterpackEntity, StarterpackConfig}; -pub use notification::{NotificationEntity, NotificationConfig, NotificationData}; \ No newline at end of file diff --git a/parakeet/src/lib.rs b/parakeet/src/lib.rs index e64bd68b..b11c2963 100644 --- a/parakeet/src/lib.rs +++ b/parakeet/src/lib.rs @@ -5,9 +5,65 @@ use diesel_async::pooled_connection::deadpool::Pool; use diesel_async::AsyncPgConnection; use std::sync::Arc; -pub mod common; +// Inline module declarations for common (replacing common/mod.rs) +pub mod common { + //! Common infrastructure and utilities shared across the application + + pub mod auth; + pub mod cache_id_helpers; + pub mod cache_listener; + pub mod cache_timeline; + pub mod errors; + pub mod helpers; + pub mod rate_limiting; + + // Re-export commonly used items + pub use auth::{AtpAcceptLabelers, AtpAuth, JwtVerifier}; + pub use cache_id_helpers::{get_actor_id_or_fetch, get_actor_dids_or_fetch, get_actor_ids_or_fetch}; + pub use cache_listener::spawn_cache_listener; + pub use cache_timeline::{AuthorFeedCache, TimelineCache}; + pub use errors::{Error, XrpcResult}; + pub use rate_limiting::{rate_limit_middleware, RateLimiter}; +} + pub mod config; -pub mod entities; + +// Inline module declarations for entities (replacing entities/mod.rs) +pub mod entities { + pub mod actor_ext; + pub mod post; + pub mod post_converter; + pub mod post_ext; + pub mod profile; + pub mod profile_converter; + pub mod feedgen; + pub mod list; + pub mod starterpack; + pub mod notification; + + #[cfg(test)] + mod profile_tests; + #[cfg(test)] + mod post_tests; + #[cfg(test)] + mod notification_tests; + #[cfg(test)] + mod list_tests; + #[cfg(test)] + mod feedgen_tests; + #[cfg(test)] + mod starterpack_tests; + + pub use actor_ext::ActorExt; + pub use post::{PostEntity, PostConfig, PostData, PostCacheStats}; + pub use post_ext::{PostExt, PostDataExt}; + pub use profile::{ProfileEntity, ProfileConfig, ProfileData, CacheStats}; + pub use feedgen::{FeedGeneratorEntity, FeedGeneratorConfig}; + pub use list::{ListEntity, ListConfig}; + pub use starterpack::{StarterpackEntity, StarterpackConfig}; + pub use notification::{NotificationEntity, NotificationConfig, NotificationData}; +} + pub mod xrpc; // Re-export entities for use in main @@ -22,8 +78,8 @@ pub struct GlobalState { pub id_cache: Arc, pub rate_limiter: Arc, pub rate_limit_config: config::ConfigRateLimit, - pub timeline_cache: Arc, - pub author_feed_cache: Arc, + pub timeline_cache: Arc, + pub author_feed_cache: Arc, pub http_client: reqwest::Client, // Entity-based system (replaces old hydration/loaders/caches) pub profile_entity: Arc, diff --git a/parakeet/src/main.rs b/parakeet/src/main.rs index 1cd1d326..7d1b6aa2 100644 --- a/parakeet/src/main.rs +++ b/parakeet/src/main.rs @@ -88,10 +88,10 @@ async fn main() -> eyre::Result<()> { let rate_limiter = Arc::new(common::rate_limiting::RateLimiter::new()); // Initialize timeline cache (60 second TTL, 10k max items) - let timeline_cache = Arc::new(common::cache::TimelineCache::new(60, 10_000)); + let timeline_cache = Arc::new(common::TimelineCache::new(60, 10_000)); // Initialize author feed cache (60 second TTL, 10k max items) - let author_feed_cache = Arc::new(common::cache::AuthorFeedCache::new(60, 10_000)); + let author_feed_cache = Arc::new(common::AuthorFeedCache::new(60, 10_000)); // Initialize new entity-centric implementations (replacing old caches) @@ -151,7 +151,7 @@ async fn main() -> eyre::Result<()> { // Spawn cache invalidation listener (PostgreSQL LISTEN/NOTIFY) // This listens for cache_invalidate notifications from the consumer - if let Err(e) = common::cache::spawn_cache_listener(Arc::new(state.clone())).await { + if let Err(e) = common::spawn_cache_listener(Arc::new(state.clone())).await { tracing::warn!("Failed to spawn cache listener: {}", e); // Continue anyway - cache will rely on TTL for freshness } diff --git a/parakeet/src/xrpc/app_bsky/actor.rs b/parakeet/src/xrpc/app_bsky/actor.rs index 2d4a1f0d..ff175a89 100644 --- a/parakeet/src/xrpc/app_bsky/actor.rs +++ b/parakeet/src/xrpc/app_bsky/actor.rs @@ -259,7 +259,7 @@ pub async fn get_suggestions( } // Convert DIDs to actor_ids for efficient profile loading - let did_to_actor_id = crate::common::cache::get_actor_ids_or_fetch( + let did_to_actor_id = crate::common::get_actor_ids_or_fetch( &state.pool, &state.id_cache, &all_dids, diff --git a/parakeet/src/xrpc/app_bsky/feed/mod.rs b/parakeet/src/xrpc/app_bsky/feed/mod.rs deleted file mode 100644 index 69dd7578..00000000 --- a/parakeet/src/xrpc/app_bsky/feed/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod feedgen; -pub mod get_timeline; -pub mod likes; -pub mod posts; -pub mod search; diff --git a/parakeet/src/xrpc/app_bsky/feed/posts/mod.rs b/parakeet/src/xrpc/app_bsky/feed/posts/mod.rs deleted file mode 100644 index d3afcc7a..00000000 --- a/parakeet/src/xrpc/app_bsky/feed/posts/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod feeds; -mod helpers; -mod queries; -mod threads; - -// Re-export public types and functions -pub use feeds::{get_author_feed, get_feed, get_list_feed}; -pub use queries::{get_posts, get_quotes, get_reposted_by}; -pub use threads::get_post_thread; diff --git a/parakeet/src/xrpc/app_bsky/graph/mod.rs b/parakeet/src/xrpc/app_bsky/graph/mod.rs deleted file mode 100644 index 97e3d677..00000000 --- a/parakeet/src/xrpc/app_bsky/graph/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod lists; -pub mod mutes; -pub mod relations; -pub mod search; -pub mod starter_packs; -pub mod suggestions; -pub mod thread_mutes; diff --git a/parakeet/src/xrpc/app_bsky/graph/thread_mutes.rs b/parakeet/src/xrpc/app_bsky/graph/thread_mutes.rs index a25087c9..22be83cc 100644 --- a/parakeet/src/xrpc/app_bsky/graph/thread_mutes.rs +++ b/parakeet/src/xrpc/app_bsky/graph/thread_mutes.rs @@ -19,7 +19,7 @@ pub async fn mute_thread( let mut conn = state.pool.get().await?; // Resolve authenticated user's actor_id via IdCache - let actor_id = crate::common::cache::get_actor_id_or_fetch( + let actor_id = crate::common::get_actor_id_or_fetch( &state.pool, &state.id_cache, &auth.0, @@ -39,7 +39,7 @@ pub async fn mute_thread( let rkey_bigint = parakeet_db::tid_util::decode_tid(rkey_str) .map_err(|_| Error::invalid_request(Some("Invalid TID in root URI".into())))?; - let root_post_actor_id = crate::common::cache::get_actor_id_or_fetch( + let root_post_actor_id = crate::common::get_actor_id_or_fetch( &state.pool, &state.id_cache, root_did, @@ -79,7 +79,7 @@ pub async fn unmute_thread( let mut conn = state.pool.get().await?; // Resolve authenticated user's actor_id via IdCache - let actor_id = crate::common::cache::get_actor_id_or_fetch( + let actor_id = crate::common::get_actor_id_or_fetch( &state.pool, &state.id_cache, &auth.0, @@ -99,7 +99,7 @@ pub async fn unmute_thread( let rkey_bigint = parakeet_db::tid_util::decode_tid(rkey_str) .map_err(|_| Error::invalid_request(Some("Invalid TID in root URI".into())))?; - let root_post_actor_id = crate::common::cache::get_actor_id_or_fetch( + let root_post_actor_id = crate::common::get_actor_id_or_fetch( &state.pool, &state.id_cache, root_did, diff --git a/parakeet/src/xrpc/app_bsky/mod.rs b/parakeet/src/xrpc/app_bsky/mod.rs index bbb9fc1d..7ad97b4e 100644 --- a/parakeet/src/xrpc/app_bsky/mod.rs +++ b/parakeet/src/xrpc/app_bsky/mod.rs @@ -4,12 +4,42 @@ use axum::Router; mod actor; mod ageassurance; mod bookmark; -mod feed; -mod graph; mod labeler; mod notification; mod unspecced; +// Inline module declarations for feed (replacing feed/mod.rs) +mod feed { + pub mod feedgen; + pub mod get_timeline; + pub mod likes; + pub mod search; + + // Inline posts module with its submodules (replacing posts/mod.rs) + pub mod posts { + mod feeds; + mod helpers; + mod queries; + mod threads; + + // Re-export public types and functions + pub use feeds::{get_author_feed, get_feed, get_list_feed}; + pub use queries::{get_posts, get_quotes, get_reposted_by}; + pub use threads::get_post_thread; + } +} + +// Inline module declarations for graph (replacing graph/mod.rs) +mod graph { + pub mod lists; + pub mod mutes; + pub mod relations; + pub mod search; + pub mod starter_packs; + pub mod suggestions; + pub mod thread_mutes; +} + #[rustfmt::skip] pub fn routes() -> Router { Router::new() diff --git a/parakeet/src/xrpc/app_bsky/notification/mod.rs b/parakeet/src/xrpc/app_bsky/notification.rs similarity index 100% rename from parakeet/src/xrpc/app_bsky/notification/mod.rs rename to parakeet/src/xrpc/app_bsky/notification.rs diff --git a/parakeet/src/xrpc/app_bsky/unspecced/mod.rs b/parakeet/src/xrpc/app_bsky/unspecced/mod.rs index cfb15e36..08efb92e 100644 --- a/parakeet/src/xrpc/app_bsky/unspecced/mod.rs +++ b/parakeet/src/xrpc/app_bsky/unspecced/mod.rs @@ -231,7 +231,7 @@ pub async fn get_suggested_users( } // Convert DIDs to actor_ids for profile loading - let actor_id_map = match crate::common::cache::get_actor_ids_or_fetch( + let actor_id_map = match crate::common::get_actor_ids_or_fetch( &state.pool, &state.id_cache, &all_dids, @@ -563,7 +563,7 @@ pub async fn get_suggested_starter_packs( // Hydrate starter packs maintaining order let (maybe_did, maybe_actor_id) = if let Some(auth) = maybe_auth { let did = auth.0.clone(); - let actor_id = crate::common::cache::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); + let actor_id = crate::common::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); (Some(did), actor_id) } else { (None, None) diff --git a/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/other_replies.rs b/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/other_replies.rs index a92b2d4d..9aafaefc 100644 --- a/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/other_replies.rs +++ b/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/other_replies.rs @@ -59,7 +59,7 @@ pub async fn get_post_thread_other_v2( let is_authenticated = maybe_auth.is_some(); let (maybe_did, maybe_actor_id) = if let Some(auth) = maybe_auth { let did = auth.0.clone(); - let actor_id = crate::common::cache::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); + let actor_id = crate::common::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); (Some(did), actor_id) } else { (None, None) diff --git a/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/post_thread.rs b/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/post_thread.rs index 79fe9da1..c3e9ba59 100644 --- a/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/post_thread.rs +++ b/parakeet/src/xrpc/app_bsky/unspecced/thread_v2/post_thread.rs @@ -28,7 +28,7 @@ pub async fn get_post_thread_v2( let is_authenticated = maybe_auth.is_some(); let (maybe_did, maybe_actor_id) = if let Some(auth) = maybe_auth { let did = auth.0.clone(); - let actor_id = crate::common::cache::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); + let actor_id = crate::common::get_actor_id_or_fetch(&state.pool, &state.id_cache, &did).await.ok(); (Some(did), actor_id) } else { (None, None) diff --git a/parakeet/src/xrpc/community_lexicon/bookmarks.rs b/parakeet/src/xrpc/community_lexicon/bookmarks.rs index aa3d81cc..f99f3d36 100644 --- a/parakeet/src/xrpc/community_lexicon/bookmarks.rs +++ b/parakeet/src/xrpc/community_lexicon/bookmarks.rs @@ -31,7 +31,7 @@ pub async fn get_actor_bookmarks( let limit = query.limit.unwrap_or(50).clamp(1, 100); // Resolve DID to actor_id via IdCache - let actor_id = crate::common::cache::get_actor_id_or_fetch( + let actor_id = crate::common::get_actor_id_or_fetch( &state.pool, &state.id_cache, &auth.0,