Merge pull request #2178 from LemmyNet/fix_ban_expires

Adding a ban expires update job. Fixes #2177
This commit is contained in:
Nutomic 2022-03-31 12:05:17 +00:00 committed by GitHub
commit 4597ea2017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 29 additions and 24 deletions

View File

@ -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 = ();

View File

@ -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 = ();

View File

@ -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::<Kind>::new(l)

View File

@ -47,7 +47,7 @@ impl Deref for ApubComment {
impl From<Comment> for ApubComment {
fn from(c: Comment) -> Self {
ApubComment { 0: c }
ApubComment(c)
}
}

View File

@ -41,7 +41,7 @@ impl Deref for ApubCommunity {
impl From<Community> for ApubCommunity {
fn from(c: Community) -> Self {
ApubCommunity { 0: c }
ApubCommunity(c)
}
}

View File

@ -37,7 +37,7 @@ impl Deref for ApubSite {
impl From<Site> for ApubSite {
fn from(s: Site) -> Self {
ApubSite { 0: s }
ApubSite(s)
}
}

View File

@ -47,7 +47,7 @@ impl Deref for ApubPerson {
impl From<DbPerson> for ApubPerson {
fn from(p: DbPerson) -> Self {
ApubPerson { 0: p }
ApubPerson(p)
}
}

View File

@ -50,7 +50,7 @@ impl Deref for ApubPost {
impl From<Post> for ApubPost {
fn from(p: Post) -> Self {
ApubPost { 0: p }
ApubPost(p)
}
}

View File

@ -40,7 +40,7 @@ impl Deref for ApubPrivateMessage {
impl From<PrivateMessage> for ApubPrivateMessage {
fn from(pm: PrivateMessage) -> Self {
ApubPrivateMessage { 0: pm }
ApubPrivateMessage(pm)
}
}

View File

@ -65,11 +65,11 @@ pub enum SearchType {
}
pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
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)
}

View File

@ -120,11 +120,7 @@ impl CommentReportView {
))
.first::<CommentReportViewTuple>(conn)?;
let my_vote = if comment_like.is_none() {
None
} else {
comment_like
};
let my_vote = comment_like;
Ok(Self {
comment_report,

View File

@ -111,7 +111,7 @@ impl PostReportView {
))
.first::<PostReportViewTuple>(conn)?;
let my_vote = if post_like.is_none() { None } else { post_like };
let my_vote = post_like;
Ok(Self {
post_report,

View File

@ -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())
}

View File

@ -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();

View File

@ -138,8 +138,7 @@ fn html_to_site_metadata(html_bytes: &[u8]) -> Result<SiteMetadata, LemmyError>
.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);

View File

@ -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 =
"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");
}