From 3ad172e8ed9e0458bb21daaa5fd745b9159a98da Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 30 Mar 2022 09:56:23 -0400 Subject: [PATCH 1/2] Adding a ban expires update job. Fixes #2177 --- src/scheduled_tasks.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index f416fb7b4..23c4fdc4a 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -13,12 +13,14 @@ pub fn setup(pool: DbPool) -> Result<(), LemmyError> { let conn = pool.get()?; active_counts(&conn); + update_banned_when_expired(&conn); // On startup, reindex the tables non-concurrently // TODO remove this for now, since it slows down startup a lot on lemmy.ml reindex_aggregates_tables(&conn, true); scheduler.every(1.hour()).run(move || { active_counts(&conn); + update_banned_when_expired(&conn); reindex_aggregates_tables(&conn, true); }); @@ -91,3 +93,13 @@ fn active_counts(conn: &PgConnection) { info!("Done."); } + +/// Set banned to false after ban expires +fn update_banned_when_expired(conn: &PgConnection) { + info!("Updating banned column if it expires ..."); + let update_ban_expires_stmt = + format!("update person set banned = false where banned = true and ban_expires < now()"); + sql_query(update_ban_expires_stmt) + .execute(conn) + .expect("update banned when expires"); +} From 4cf0da7b60b68027f29a49a8a518f266c3084463 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 30 Mar 2022 10:58:03 -0400 Subject: [PATCH 2/2] Clippy fixes. --- crates/apub/src/collections/community_moderators.rs | 4 ++-- crates/apub/src/collections/community_outbox.rs | 2 +- crates/apub/src/fetcher/webfinger.rs | 3 +-- crates/apub/src/objects/comment.rs | 2 +- crates/apub/src/objects/community.rs | 2 +- crates/apub/src/objects/instance.rs | 2 +- crates/apub/src/objects/person.rs | 2 +- crates/apub/src/objects/post.rs | 2 +- crates/apub/src/objects/private_message.rs | 2 +- crates/db_schema/src/lib.rs | 4 ++-- crates/db_views/src/comment_report_view.rs | 6 +----- crates/db_views/src/post_report_view.rs | 2 +- crates/routes/src/feeds.rs | 2 +- crates/routes/src/webfinger.rs | 3 +-- crates/utils/src/request.rs | 3 +-- src/scheduled_tasks.rs | 2 +- 16 files changed, 18 insertions(+), 25 deletions(-) diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index 528254826..b0182bdf2 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -41,7 +41,7 @@ impl ApubObject for ApubCommunityModerators { CommunityModeratorView::for_community(conn, cid) }) .await??; - Ok(Some(ApubCommunityModerators { 0: moderators })) + Ok(Some(ApubCommunityModerators(moderators))) } else { Ok(None) } @@ -131,7 +131,7 @@ impl ApubObject for ApubCommunityModerators { } // This return value is unused, so just set an empty vec - Ok(ApubCommunityModerators { 0: vec![] }) + Ok(ApubCommunityModerators(Vec::new())) } type DbType = (); diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 3b4c8534d..f33034061 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -116,7 +116,7 @@ impl ApubObject for ApubCommunityOutbox { } // This return value is unused, so just set an empty vec - Ok(ApubCommunityOutbox { 0: vec![] }) + Ok(ApubCommunityOutbox(Vec::new())) } type DbType = (); diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 918e1de0f..e2370c329 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -73,8 +73,7 @@ where false } }) - .map(|l| l.href.clone()) - .flatten() + .filter_map(|l| l.href.clone()) .collect(); for l in links { let object = ObjectId::::new(l) diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index bc8caceaa..c622c14dd 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -47,7 +47,7 @@ impl Deref for ApubComment { impl From for ApubComment { fn from(c: Comment) -> Self { - ApubComment { 0: c } + ApubComment(c) } } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index eb9cb218b..bbb239cb5 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -41,7 +41,7 @@ impl Deref for ApubCommunity { impl From for ApubCommunity { fn from(c: Community) -> Self { - ApubCommunity { 0: c } + ApubCommunity(c) } } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 9968b81e1..af75812da 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -37,7 +37,7 @@ impl Deref for ApubSite { impl From for ApubSite { fn from(s: Site) -> Self { - ApubSite { 0: s } + ApubSite(s) } } diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index a903d5a65..a6133ed47 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -47,7 +47,7 @@ impl Deref for ApubPerson { impl From for ApubPerson { fn from(p: DbPerson) -> Self { - ApubPerson { 0: p } + ApubPerson(p) } } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index d5309dc17..dbea0349c 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -50,7 +50,7 @@ impl Deref for ApubPost { impl From for ApubPost { fn from(p: Post) -> Self { - ApubPost { 0: p } + ApubPost(p) } } diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 6f445184a..04974b802 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -40,7 +40,7 @@ impl Deref for ApubPrivateMessage { impl From for ApubPrivateMessage { fn from(pm: PrivateMessage) -> Self { - ApubPrivateMessage { 0: pm } + ApubPrivateMessage(pm) } } diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 5388d37c2..724fffcd4 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -65,11 +65,11 @@ pub enum SearchType { } pub fn from_opt_str_to_opt_enum(opt: &Option) -> Option { - opt.as_ref().map(|t| T::from_str(t).ok()).flatten() + opt.as_ref().and_then(|t| T::from_str(t).ok()) } pub fn fuzzy_search(q: &str) -> String { - let replaced = q.replace("%", "\\%").replace("_", "\\_").replace(" ", "%"); + let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%"); format!("%{}%", replaced) } diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 68c000271..63701db93 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -120,11 +120,7 @@ impl CommentReportView { )) .first::(conn)?; - let my_vote = if comment_like.is_none() { - None - } else { - comment_like - }; + let my_vote = comment_like; Ok(Self { comment_report, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index e8532a916..66341d67b 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -111,7 +111,7 @@ impl PostReportView { )) .first::(conn)?; - let my_vote = if post_like.is_none() { None } else { post_like }; + let my_vote = post_like; Ok(Self { post_report, diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 8fee23959..bfe49fbdb 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -373,7 +373,7 @@ fn build_item( i.guid(guid); i.link(url.to_owned()); // TODO add images - let html = markdown_to_html(&content.to_string()); + let html = markdown_to_html(content); i.description(html); Ok(i.build()) } diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index b31553793..a95902b27 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -39,8 +39,7 @@ async fn get_webfinger_response( .settings() .webfinger_regex() .captures(&info.resource) - .map(|c| c.get(1)) - .flatten() + .and_then(|c| c.get(1)) .context(location_info!())? .as_str() .to_string(); diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index 1e4f4bf3c..c0593ffa1 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -138,8 +138,7 @@ fn html_to_site_metadata(html_bytes: &[u8]) -> Result .opengraph .images .get(0) - .map(|ogo| Url::parse(&ogo.url).ok()) - .flatten(); + .and_then(|ogo| Url::parse(&ogo.url).ok()); let title = og_title.or(page_title); let description = og_description.or(page_description); diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 23c4fdc4a..30e553b56 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -98,7 +98,7 @@ fn active_counts(conn: &PgConnection) { fn update_banned_when_expired(conn: &PgConnection) { info!("Updating banned column if it expires ..."); let update_ban_expires_stmt = - format!("update person set banned = false where banned = true and ban_expires < now()"); + "update person set banned = false where banned = true and ban_expires < now()"; sql_query(update_ban_expires_stmt) .execute(conn) .expect("update banned when expires");