diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index d0039d1f8..8e5419c7e 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -69,19 +69,7 @@ impl Collection for ApubCommunityModerators { community_id: mod_user.community.id, person_id: mod_user.moderator.id, }; - let c = CommunityModerator::leave(&mut data.pool(), &community_moderator_form).await?; - assert_eq!(c.deleted + c.updated, 1); - } - } - for mod_user in ¤t_moderators { - let mod_id = ObjectId::from(mod_user.moderator.actor_id.clone()); - if !apub.ordered_items.contains(&mod_id) { - let community_moderator_form = CommunityModeratorForm { - community_id: mod_user.community.id, - person_id: mod_user.moderator.id, - }; - let c = CommunityModerator::leave(&mut data.pool(), &community_moderator_form).await?; - panic!("pain"); + CommunityModerator::leave(&mut data.pool(), &community_moderator_form).await?; } } diff --git a/crates/db_schema/src/utils/uplete.rs b/crates/db_schema/src/utils/uplete.rs index 015068fc6..14f52eece 100644 --- a/crates/db_schema/src/utils/uplete.rs +++ b/crates/db_schema/src/utils/uplete.rs @@ -129,7 +129,7 @@ impl QueryFragment for UpleteQuery { out.push_sql(prefix); out.push_sql(" AS ("); subquery.walk_ast(out.reborrow())?; - out.push_sql(" )"); + out.push_sql(" FOR UPDATE)"); } // Update rows that are referenced in `update_keys` @@ -151,13 +151,11 @@ impl QueryFragment for UpleteQuery { self.table.walk_ast(out.reborrow())?; out.push_sql(" WHERE ("); self.primary_key.walk_ast(out.reborrow())?; - out.push_sql(") = ANY (SELECT * FROM update_keys) RETURNING 1)"); + out.push_sql(") = ANY (SELECT * FROM delete_keys) RETURNING 1)"); // Count updated rows and deleted rows (`RETURNING 1` makes this possible) - //out.push_sql(" SELECT (SELECT count(*) FROM update_result)"); - //out.push_sql(", (SELECT count(*) FROM delete_result)"); - out.push_sql(" SELECT (SELECT count(*) FROM update_keys)"); - out.push_sql(", (SELECT count(*) FROM delete_keys)"); + out.push_sql(" SELECT (SELECT count(*) FROM update_result)"); + out.push_sql(", (SELECT count(*) FROM delete_result)"); Ok(()) } diff --git a/crates/db_views_actor/src/community_moderator_view.rs b/crates/db_views_actor/src/community_moderator_view.rs index 4ce912bf7..47f4ab104 100644 --- a/crates/db_views_actor/src/community_moderator_view.rs +++ b/crates/db_views_actor/src/community_moderator_view.rs @@ -40,13 +40,11 @@ impl CommunityModeratorView { pool: &mut DbPool<'_>, community_id: CommunityId, ) -> Result, Error> { - use diesel::NullableExpressionMethods; let conn = &mut get_conn(pool).await?; action_query(community_actions::became_moderator) .inner_join(community::table) .inner_join(person::table) .filter(community_actions::community_id.eq(community_id)) - .filter(community_actions::became_moderator.is_not_null()) .select((community::all_columns, person::all_columns)) .order_by(community_actions::became_moderator) .load::(conn) diff --git a/migrations/2024-03-17-134311_smoosh-tables-together/down.sql b/migrations/2024-05-31-134311_smoosh-tables-together/down.sql similarity index 97% rename from migrations/2024-03-17-134311_smoosh-tables-together/down.sql rename to migrations/2024-05-31-134311_smoosh-tables-together/down.sql index 38a273747..01cf9ef7e 100644 --- a/migrations/2024-03-17-134311_smoosh-tables-together/down.sql +++ b/migrations/2024-05-31-134311_smoosh-tables-together/down.sql @@ -254,14 +254,10 @@ ALTER INDEX comment_actions_pkey RENAME TO comment_like_pkey; ALTER INDEX idx_comment_actions_comment RENAME TO idx_comment_like_comment; -ALTER INDEX idx_comment_actions_post RENAME TO idx_comment_like_post; - ALTER TABLE comment_like RENAME CONSTRAINT comment_actions_comment_id_fkey TO comment_like_comment_id_fkey; ALTER TABLE comment_like RENAME CONSTRAINT comment_actions_person_id_fkey TO comment_like_person_id_fkey; -ALTER TABLE comment_like RENAME CONSTRAINT comment_actions_post_id_fkey TO comment_like_post_id_fkey; - ALTER INDEX community_actions_pkey RENAME TO community_follower_pkey; ALTER INDEX idx_community_actions_community RENAME TO idx_community_follower_community; @@ -298,8 +294,6 @@ CREATE INDEX idx_comment_saved_comment ON comment_saved (comment_id); CREATE INDEX idx_comment_saved_person ON comment_saved (person_id); -CREATE INDEX idx_comment_like_post ON comment_like (post_id); - CREATE INDEX idx_community_block_community ON community_block (community_id); CREATE INDEX idx_community_moderator_community ON community_moderator (community_id); diff --git a/migrations/2024-03-17-134311_smoosh-tables-together/up.sql b/migrations/2024-05-31-134311_smoosh-tables-together/up.sql similarity index 99% rename from migrations/2024-03-17-134311_smoosh-tables-together/up.sql rename to migrations/2024-05-31-134311_smoosh-tables-together/up.sql index e9127d11a..ac1b66a20 100644 --- a/migrations/2024-03-17-134311_smoosh-tables-together/up.sql +++ b/migrations/2024-05-31-134311_smoosh-tables-together/up.sql @@ -53,7 +53,7 @@ ALTER TABLE community_actions ADD COLUMN received_ban timestamptz, ADD COLUMN ban_expires timestamptz, ADD CONSTRAINT community_actions_check_followed CHECK ((followed IS NULL) = (follow_pending IS NULL)), - ADD CONSTRAINT community_actions_check_received_ban CHECK ((received_ban IS NULL, ban_expires IS NULL) != (TRUE, FALSE)); + ADD CONSTRAINT community_actions_check_received_ban CHECK (NOT (received_ban IS NULL AND ban_expires IS NOT NULL)); ALTER TABLE instance_actions ALTER COLUMN blocked DROP NOT NULL,