diff --git a/src/db/graph/exec.rs b/src/db/graph/exec.rs index 8e0d825f..b7aa9274 100644 --- a/src/db/graph/exec.rs +++ b/src/db/graph/exec.rs @@ -8,9 +8,9 @@ use serde::de::DeserializeOwned; pub enum OperationOutcome { /// The query found and updated an existing node/relationship. Updated, - /// The query changed the existence state of a node/relationship - /// (i.e., it was created or deleted). - ExistenceChanged, + /// This variant represents a structural mutation where the node/relationship + /// did not exist before the operation (creation) or no longer exists after the operation (deletion) + CreatedOrDeleted, /// A required node/relationship was not found, indicating a missing dependency /// (often due to the node/relationship not yet being indexed or otherwise unavailable). Pending, @@ -20,7 +20,7 @@ pub enum OperationOutcome { /// "flag". Interprets the boolean as follows: /// /// - `true` => Returns [`OperationOutcome::Updated`] -/// - `false` => Returns [`OperationOutcome::ExistenceChanged`] +/// - `false` => Returns [`OperationOutcome::CreatedOrDeleted`] /// /// If no rows are returned, this function returns [`OperationOutcome::Pending`], typically /// indicating a missing dependency or an unmatched query condition. @@ -36,7 +36,7 @@ pub async fn execute_graph_operation(query: Query) -> Result match row.get("flag")? { true => Ok(OperationOutcome::Updated), - false => Ok(OperationOutcome::ExistenceChanged), + false => Ok(OperationOutcome::CreatedOrDeleted), }, None => Ok(OperationOutcome::Pending), } diff --git a/src/events/handlers/bookmark.rs b/src/events/handlers/bookmark.rs index ae772509..821961bf 100644 --- a/src/events/handlers/bookmark.rs +++ b/src/events/handlers/bookmark.rs @@ -37,7 +37,7 @@ pub async fn sync_put( let indexed_at = Utc::now().timestamp_millis(); let existed = match Bookmark::put_to_graph(&author_id, &post_id, &user_id, &id, indexed_at).await? { - OperationOutcome::ExistenceChanged => false, + OperationOutcome::CreatedOrDeleted => false, OperationOutcome::Updated => true, // TODO: Should return an error that should be processed by RetryManager OperationOutcome::Pending => { diff --git a/src/events/handlers/follow.rs b/src/events/handlers/follow.rs index 8dd4e067..2ad88a2a 100644 --- a/src/events/handlers/follow.rs +++ b/src/events/handlers/follow.rs @@ -29,7 +29,7 @@ pub async fn sync_put(follower_id: PubkyId, followee_id: PubkyId) -> Result<(), return Err("WATCHER: Missing some dependency to index the model".into()) } // The relationship did not exist, create all related indexes - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // Checks whether the followee was following the follower (Is this a new friendship?) let will_be_friends = is_followee_following_follower(&follower_id, &followee_id).await?; @@ -74,7 +74,7 @@ pub async fn sync_del(follower_id: PubkyId, followee_id: PubkyId) -> Result<(), OperationOutcome::Pending => { Err("WATCHER: Missing some dependency to index the model".into()) } - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // Check if the users are friends. Is this a break? :( let were_friends = Friends::check(&follower_id, &followee_id).await?; diff --git a/src/events/handlers/mute.rs b/src/events/handlers/mute.rs index e6d13f64..cc33cb19 100644 --- a/src/events/handlers/mute.rs +++ b/src/events/handlers/mute.rs @@ -23,7 +23,7 @@ pub async fn sync_put(user_id: PubkyId, muted_id: PubkyId) -> Result<(), DynErro OperationOutcome::Pending => { Err("WATCHER: Missing some dependency to index the model".into()) } - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // SAVE TO INDEX Muted(vec![muted_id.to_string()]) .put_to_index(&user_id) @@ -45,7 +45,7 @@ pub async fn sync_del(user_id: PubkyId, muted_id: PubkyId) -> Result<(), DynErro OperationOutcome::Pending => { Err("WATCHER: Missing some dependency to index the model".into()) } - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // REMOVE FROM INDEX Muted(vec![muted_id.to_string()]) .del_from_index(&user_id) diff --git a/src/events/handlers/post.rs b/src/events/handlers/post.rs index ad990194..d4480639 100644 --- a/src/events/handlers/post.rs +++ b/src/events/handlers/post.rs @@ -39,7 +39,7 @@ pub async fn sync_put( let mut post_relationships = PostRelationships::from_homeserver(&post); let existed = match post_details.put_to_graph(&post_relationships).await? { - OperationOutcome::ExistenceChanged => false, + OperationOutcome::CreatedOrDeleted => false, OperationOutcome::Updated => true, // TODO: Should return an error that should be processed by RetryManager // WIP: Create a custom error type to pass enough info to the RetryManager @@ -251,11 +251,11 @@ pub async fn del(author_id: PubkyId, post_id: String) -> Result<(), DynError> { // Graph query to check if there is any edge at all to this post other than AUTHORED, is a reply or is a repost. let query = post_is_safe_to_delete(&author_id, &post_id); - // If there is none other relationship (OperationOutcome::ExistenceChanged), we delete from graph and redis. + // If there is none other relationship (OperationOutcome::CreatedOrDeleted), we delete from graph and redis. // But if there is any (OperationOutcome::Updated), then we simply update the post with keyword content [DELETED]. // A deleted post is a post whose content is EXACTLY `"[DELETED]"` match execute_graph_operation(query).await? { - OperationOutcome::ExistenceChanged => sync_del(author_id, post_id).await?, + OperationOutcome::CreatedOrDeleted => sync_del(author_id, post_id).await?, OperationOutcome::Updated => { let existing_relationships = PostRelationships::get_by_id(&author_id, &post_id).await?; let parent = match existing_relationships { diff --git a/src/events/handlers/tag.rs b/src/events/handlers/tag.rs index c19cbf55..39bde6fc 100644 --- a/src/events/handlers/tag.rs +++ b/src/events/handlers/tag.rs @@ -84,7 +84,7 @@ async fn put_sync_post( OperationOutcome::Pending => { Err("WATCHER: Missing some dependency to index the model".into()) } - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // SAVE TO INDEXES let post_key_slice: &[&str] = &[&author_id, &post_id]; @@ -163,7 +163,7 @@ async fn put_sync_user( OperationOutcome::Pending => { Err("WATCHER: Missing some dependency to index the model".into()) } - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { // SAVE TO INDEX // Update user counts for the tagged user UserCounts::update(&tagged_user_id, "tagged", JsonAction::Increment(1)).await?; diff --git a/src/events/handlers/user.rs b/src/events/handlers/user.rs index bbc65ae7..d2ee1b79 100644 --- a/src/events/handlers/user.rs +++ b/src/events/handlers/user.rs @@ -43,12 +43,12 @@ pub async fn del(user_id: PubkyId) -> Result<(), DynError> { // 1. Graph query to check if there is any edge at all to this user. let query = user_is_safe_to_delete(&user_id); - // 2. If there is no relationships (OperationOutcome::ExistenceChanged), delete from graph and redis. + // 2. If there is no relationships (OperationOutcome::CreatedOrDeleted), delete from graph and redis. // 3. But if there is any relationship (OperationOutcome::Updated), then we simply update the user with empty profile // and keyword username [DELETED]. // A deleted user is a user whose profile is empty and has username `"[DELETED]"` match execute_graph_operation(query).await? { - OperationOutcome::ExistenceChanged => { + OperationOutcome::CreatedOrDeleted => { UserDetails::delete(&user_id).await?; UserCounts::delete(&user_id).await?; } diff --git a/src/events/mod.rs b/src/events/mod.rs index d782c477..46e37fac 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -52,7 +52,9 @@ pub struct Event { } impl Event { - pub fn from_str(line: &str) -> Result, Box> { + pub fn parse_event( + line: &str, + ) -> Result, Box> { debug!("New event: {}", line); let parts: Vec<&str> = line.split(' ').collect(); if parts.len() != 2 { diff --git a/src/events/processor.rs b/src/events/processor.rs index 1601e2e1..2de553b3 100644 --- a/src/events/processor.rs +++ b/src/events/processor.rs @@ -92,7 +92,7 @@ impl EventProcessor { info!("Cursor for the next request: {}", cursor); } } else { - let event = match Event::from_str(line) { + let event = match Event::parse_event(line) { Ok(event) => event, Err(e) => { error!("Error while creating event line from line: {}", e);