+
+ pub fn fetch_pictrs_posts_for_creator(
+ conn: &PgConnection,
+ for_creator_id: PersonId,
+ ) -> Result<Vec<Self>, Error> {
+ use crate::schema::post::dsl::*;
+ let pictrs_search = "%pictrs/image%";
+
+ post
+ .filter(creator_id.eq(for_creator_id))
+ .filter(url.like(pictrs_search))
+ .load::<Self>(conn)
+ }
+
+ /// Sets the url and thumbnails fields to None
+ pub fn remove_pictrs_post_images_and_thumbnails_for_creator(
+ conn: &PgConnection,
+ for_creator_id: PersonId,
+ ) -> Result<Vec<Self>, Error> {
+ use crate::schema::post::dsl::*;
+ let pictrs_search = "%pictrs/image%";
+
+ diesel::update(
+ post
+ .filter(creator_id.eq(for_creator_id))
+ .filter(url.like(pictrs_search)),
+ )
+ .set((
+ url.eq::<Option<String>>(None),
+ thumbnail_url.eq::<Option<String>>(None),
+ ))
+ .get_results::<Self>(conn)
+ }
+
+ pub fn fetch_pictrs_posts_for_community(
+ conn: &PgConnection,
+ for_community_id: CommunityId,
+ ) -> Result<Vec<Self>, Error> {
+ use crate::schema::post::dsl::*;
+ let pictrs_search = "%pictrs/image%";
+ post
+ .filter(community_id.eq(for_community_id))
+ .filter(url.like(pictrs_search))
+ .load::<Self>(conn)
+ }
+
+ /// Sets the url and thumbnails fields to None
+ pub fn remove_pictrs_post_images_and_thumbnails_for_community(
+ conn: &PgConnection,
+ for_community_id: CommunityId,
+ ) -> Result<Vec<Self>, Error> {
+ use crate::schema::post::dsl::*;
+ let pictrs_search = "%pictrs/image%";
+
+ diesel::update(
+ post
+ .filter(community_id.eq(for_community_id))
+ .filter(url.like(pictrs_search)),
+ )
+ .set((
+ url.eq::<Option<String>>(None),
+ thumbnail_url.eq::<Option<String>>(None),
+ ))
+ .get_results::<Self>(conn)
+ }