mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Merge pull request #2178 from LemmyNet/fix_ban_expires
Adding a ban expires update job. Fixes #2177
This commit is contained in:
commit
4597ea2017
@ -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 = ();
|
||||
|
@ -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 = ();
|
||||
|
@ -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)
|
||||
|
@ -47,7 +47,7 @@ impl Deref for ApubComment {
|
||||
|
||||
impl From<Comment> for ApubComment {
|
||||
fn from(c: Comment) -> Self {
|
||||
ApubComment { 0: c }
|
||||
ApubComment(c)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ impl Deref for ApubCommunity {
|
||||
|
||||
impl From<Community> for ApubCommunity {
|
||||
fn from(c: Community) -> Self {
|
||||
ApubCommunity { 0: c }
|
||||
ApubCommunity(c)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl Deref for ApubSite {
|
||||
|
||||
impl From<Site> for ApubSite {
|
||||
fn from(s: Site) -> Self {
|
||||
ApubSite { 0: s }
|
||||
ApubSite(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ impl Deref for ApubPerson {
|
||||
|
||||
impl From<DbPerson> for ApubPerson {
|
||||
fn from(p: DbPerson) -> Self {
|
||||
ApubPerson { 0: p }
|
||||
ApubPerson(p)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ impl Deref for ApubPost {
|
||||
|
||||
impl From<Post> for ApubPost {
|
||||
fn from(p: Post) -> Self {
|
||||
ApubPost { 0: p }
|
||||
ApubPost(p)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ impl Deref for ApubPrivateMessage {
|
||||
|
||||
impl From<PrivateMessage> for ApubPrivateMessage {
|
||||
fn from(pm: PrivateMessage) -> Self {
|
||||
ApubPrivateMessage { 0: pm }
|
||||
ApubPrivateMessage(pm)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user