]> Untitled Git - lemmy.git/blob - crates/db_views/src/comment_view.rs
f3d5c798ae7496feb4ae82d1e45dfd5c3c6cbc02
[lemmy.git] / crates / db_views / src / comment_view.rs
1 use crate::structs::CommentView;
2 use diesel::{dsl::*, result::Error, *};
3 use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions};
4 use lemmy_db_schema::{
5   aggregates::structs::CommentAggregates,
6   newtypes::{CommentId, CommunityId, DbUrl, PersonId, PostId},
7   schema::{
8     comment,
9     comment_aggregates,
10     comment_like,
11     comment_saved,
12     community,
13     community_block,
14     community_follower,
15     community_person_ban,
16     person,
17     person_block,
18     post,
19   },
20   source::{
21     comment::{Comment, CommentSaved},
22     community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
23     person::{Person, PersonSafe},
24     person_block::PersonBlock,
25     post::Post,
26   },
27   traits::{MaybeOptional, ToSafe, ViewToVec},
28   utils::{functions::hot_rank, fuzzy_search, limit_and_offset_unlimited},
29   CommentSortType,
30   ListingType,
31 };
32
33 type CommentViewTuple = (
34   Comment,
35   PersonSafe,
36   Post,
37   CommunitySafe,
38   CommentAggregates,
39   Option<CommunityPersonBan>,
40   Option<CommunityFollower>,
41   Option<CommentSaved>,
42   Option<PersonBlock>,
43   Option<i16>,
44 );
45
46 impl CommentView {
47   pub fn read(
48     conn: &PgConnection,
49     comment_id: CommentId,
50     my_person_id: Option<PersonId>,
51   ) -> Result<Self, Error> {
52     // The left join below will return None in this case
53     let person_id_join = my_person_id.unwrap_or(PersonId(-1));
54
55     let (
56       comment,
57       creator,
58       post,
59       community,
60       counts,
61       creator_banned_from_community,
62       follower,
63       saved,
64       creator_blocked,
65       comment_like,
66     ) = comment::table
67       .find(comment_id)
68       .inner_join(person::table)
69       .inner_join(post::table)
70       .inner_join(community::table.on(post::community_id.eq(community::id)))
71       .inner_join(comment_aggregates::table)
72       .left_join(
73         community_person_ban::table.on(
74           community::id
75             .eq(community_person_ban::community_id)
76             .and(community_person_ban::person_id.eq(comment::creator_id))
77             .and(
78               community_person_ban::expires
79                 .is_null()
80                 .or(community_person_ban::expires.gt(now)),
81             ),
82         ),
83       )
84       .left_join(
85         community_follower::table.on(
86           post::community_id
87             .eq(community_follower::community_id)
88             .and(community_follower::person_id.eq(person_id_join)),
89         ),
90       )
91       .left_join(
92         comment_saved::table.on(
93           comment::id
94             .eq(comment_saved::comment_id)
95             .and(comment_saved::person_id.eq(person_id_join)),
96         ),
97       )
98       .left_join(
99         person_block::table.on(
100           comment::creator_id
101             .eq(person_block::target_id)
102             .and(person_block::person_id.eq(person_id_join)),
103         ),
104       )
105       .left_join(
106         comment_like::table.on(
107           comment::id
108             .eq(comment_like::comment_id)
109             .and(comment_like::person_id.eq(person_id_join)),
110         ),
111       )
112       .select((
113         comment::all_columns,
114         Person::safe_columns_tuple(),
115         post::all_columns,
116         Community::safe_columns_tuple(),
117         comment_aggregates::all_columns,
118         community_person_ban::all_columns.nullable(),
119         community_follower::all_columns.nullable(),
120         comment_saved::all_columns.nullable(),
121         person_block::all_columns.nullable(),
122         comment_like::score.nullable(),
123       ))
124       .first::<CommentViewTuple>(conn)?;
125
126     // If a person is given, then my_vote, if None, should be 0, not null
127     // Necessary to differentiate between other person's votes
128     let my_vote = if my_person_id.is_some() && comment_like.is_none() {
129       Some(0)
130     } else {
131       comment_like
132     };
133
134     Ok(CommentView {
135       comment,
136       post,
137       creator,
138       community,
139       counts,
140       creator_banned_from_community: creator_banned_from_community.is_some(),
141       subscribed: CommunityFollower::to_subscribed_type(&follower),
142       saved: saved.is_some(),
143       creator_blocked: creator_blocked.is_some(),
144       my_vote,
145     })
146   }
147 }
148
149 pub struct CommentQueryBuilder<'a> {
150   conn: &'a PgConnection,
151   listing_type: Option<ListingType>,
152   sort: Option<CommentSortType>,
153   community_id: Option<CommunityId>,
154   community_actor_id: Option<DbUrl>,
155   post_id: Option<PostId>,
156   parent_path: Option<Ltree>,
157   creator_id: Option<PersonId>,
158   my_person_id: Option<PersonId>,
159   search_term: Option<String>,
160   saved_only: Option<bool>,
161   show_bot_accounts: Option<bool>,
162   page: Option<i64>,
163   limit: Option<i64>,
164   max_depth: Option<i32>,
165 }
166
167 impl<'a> CommentQueryBuilder<'a> {
168   pub fn create(conn: &'a PgConnection) -> Self {
169     CommentQueryBuilder {
170       conn,
171       listing_type: Some(ListingType::All),
172       sort: None,
173       community_id: None,
174       community_actor_id: None,
175       post_id: None,
176       parent_path: None,
177       creator_id: None,
178       my_person_id: None,
179       search_term: None,
180       saved_only: None,
181       show_bot_accounts: None,
182       page: None,
183       limit: None,
184       max_depth: None,
185     }
186   }
187
188   pub fn listing_type<T: MaybeOptional<ListingType>>(mut self, listing_type: T) -> Self {
189     self.listing_type = listing_type.get_optional();
190     self
191   }
192
193   pub fn sort<T: MaybeOptional<CommentSortType>>(mut self, sort: T) -> Self {
194     self.sort = sort.get_optional();
195     self
196   }
197
198   pub fn post_id<T: MaybeOptional<PostId>>(mut self, post_id: T) -> Self {
199     self.post_id = post_id.get_optional();
200     self
201   }
202
203   pub fn creator_id<T: MaybeOptional<PersonId>>(mut self, creator_id: T) -> Self {
204     self.creator_id = creator_id.get_optional();
205     self
206   }
207
208   pub fn community_id<T: MaybeOptional<CommunityId>>(mut self, community_id: T) -> Self {
209     self.community_id = community_id.get_optional();
210     self
211   }
212
213   pub fn my_person_id<T: MaybeOptional<PersonId>>(mut self, my_person_id: T) -> Self {
214     self.my_person_id = my_person_id.get_optional();
215     self
216   }
217
218   pub fn community_actor_id<T: MaybeOptional<DbUrl>>(mut self, community_actor_id: T) -> Self {
219     self.community_actor_id = community_actor_id.get_optional();
220     self
221   }
222
223   pub fn search_term<T: MaybeOptional<String>>(mut self, search_term: T) -> Self {
224     self.search_term = search_term.get_optional();
225     self
226   }
227
228   pub fn saved_only<T: MaybeOptional<bool>>(mut self, saved_only: T) -> Self {
229     self.saved_only = saved_only.get_optional();
230     self
231   }
232
233   pub fn show_bot_accounts<T: MaybeOptional<bool>>(mut self, show_bot_accounts: T) -> Self {
234     self.show_bot_accounts = show_bot_accounts.get_optional();
235     self
236   }
237
238   pub fn parent_path<T: MaybeOptional<Ltree>>(mut self, parent_path: T) -> Self {
239     self.parent_path = parent_path.get_optional();
240     self
241   }
242
243   pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
244     self.page = page.get_optional();
245     self
246   }
247
248   pub fn limit<T: MaybeOptional<i64>>(mut self, limit: T) -> Self {
249     self.limit = limit.get_optional();
250     self
251   }
252
253   pub fn max_depth<T: MaybeOptional<i32>>(mut self, max_depth: T) -> Self {
254     self.max_depth = max_depth.get_optional();
255     self
256   }
257
258   pub fn list(self) -> Result<Vec<CommentView>, Error> {
259     use diesel::dsl::*;
260
261     // The left join below will return None in this case
262     let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
263
264     let mut query = comment::table
265       .inner_join(person::table)
266       .inner_join(post::table)
267       .inner_join(community::table.on(post::community_id.eq(community::id)))
268       .inner_join(comment_aggregates::table)
269       .left_join(
270         community_person_ban::table.on(
271           community::id
272             .eq(community_person_ban::community_id)
273             .and(community_person_ban::person_id.eq(comment::creator_id))
274             .and(
275               community_person_ban::expires
276                 .is_null()
277                 .or(community_person_ban::expires.gt(now)),
278             ),
279         ),
280       )
281       .left_join(
282         community_follower::table.on(
283           post::community_id
284             .eq(community_follower::community_id)
285             .and(community_follower::person_id.eq(person_id_join)),
286         ),
287       )
288       .left_join(
289         comment_saved::table.on(
290           comment::id
291             .eq(comment_saved::comment_id)
292             .and(comment_saved::person_id.eq(person_id_join)),
293         ),
294       )
295       .left_join(
296         person_block::table.on(
297           comment::creator_id
298             .eq(person_block::target_id)
299             .and(person_block::person_id.eq(person_id_join)),
300         ),
301       )
302       .left_join(
303         community_block::table.on(
304           community::id
305             .eq(community_block::community_id)
306             .and(community_block::person_id.eq(person_id_join)),
307         ),
308       )
309       .left_join(
310         comment_like::table.on(
311           comment::id
312             .eq(comment_like::comment_id)
313             .and(comment_like::person_id.eq(person_id_join)),
314         ),
315       )
316       .select((
317         comment::all_columns,
318         Person::safe_columns_tuple(),
319         post::all_columns,
320         Community::safe_columns_tuple(),
321         comment_aggregates::all_columns,
322         community_person_ban::all_columns.nullable(),
323         community_follower::all_columns.nullable(),
324         comment_saved::all_columns.nullable(),
325         person_block::all_columns.nullable(),
326         comment_like::score.nullable(),
327       ))
328       .into_boxed();
329
330     if let Some(creator_id) = self.creator_id {
331       query = query.filter(comment::creator_id.eq(creator_id));
332     };
333
334     if let Some(post_id) = self.post_id {
335       query = query.filter(comment::post_id.eq(post_id));
336     };
337
338     if let Some(parent_path) = self.parent_path.as_ref() {
339       query = query.filter(comment::path.contained_by(parent_path));
340     };
341
342     if let Some(search_term) = self.search_term {
343       query = query.filter(comment::content.ilike(fuzzy_search(&search_term)));
344     };
345
346     if let Some(listing_type) = self.listing_type {
347       match listing_type {
348         ListingType::Subscribed => {
349           query = query.filter(community_follower::person_id.is_not_null())
350         } // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
351         ListingType::Local => {
352           query = query.filter(community::local.eq(true)).filter(
353             community::hidden
354               .eq(false)
355               .or(community_follower::person_id.eq(person_id_join)),
356           )
357         }
358         ListingType::All => {
359           query = query.filter(
360             community::hidden
361               .eq(false)
362               .or(community_follower::person_id.eq(person_id_join)),
363           )
364         }
365       }
366     };
367
368     if let Some(community_id) = self.community_id {
369       query = query.filter(post::community_id.eq(community_id));
370     }
371
372     if let Some(community_actor_id) = self.community_actor_id {
373       query = query.filter(community::actor_id.eq(community_actor_id))
374     }
375
376     if self.saved_only.unwrap_or(false) {
377       query = query.filter(comment_saved::id.is_not_null());
378     }
379
380     if !self.show_bot_accounts.unwrap_or(true) {
381       query = query.filter(person::bot_account.eq(false));
382     };
383
384     // Don't show blocked communities or persons
385     if self.my_person_id.is_some() {
386       query = query.filter(community_block::person_id.is_null());
387       query = query.filter(person_block::person_id.is_null());
388     }
389
390     // A Max depth given means its a tree fetch
391     let (limit, offset) = if let Some(max_depth) = self.max_depth {
392       let depth_limit = if let Some(parent_path) = self.parent_path.as_ref() {
393         parent_path.0.split('.').count() as i32 + max_depth
394         // Add one because of root "0"
395       } else {
396         max_depth + 1
397       };
398
399       query = query.filter(nlevel(comment::path).le(depth_limit));
400
401       // Always order by the parent path first
402       query = query.order_by(subpath(comment::path, 0, -1));
403
404       // TODO limit question. Limiting does not work for comment threads ATM, only max_depth
405       // For now, don't do any limiting for tree fetches
406       // https://stackoverflow.com/questions/72983614/postgres-ltree-how-to-limit-the-max-number-of-children-at-any-given-level
407
408       // Don't use the regular error-checking one, many more comments must ofter be fetched.
409       // This does not work for comment trees, and the limit should be manually set to a high number
410       //
411       // If a max depth is given, then you know its a tree fetch, and limits should be ignored
412       (i64::MAX, 0)
413     } else {
414       limit_and_offset_unlimited(self.page, self.limit)
415     };
416
417     query = match self.sort.unwrap_or(CommentSortType::Hot) {
418       CommentSortType::Hot => query
419         .then_order_by(hot_rank(comment_aggregates::score, comment_aggregates::published).desc())
420         .then_order_by(comment_aggregates::published.desc()),
421       CommentSortType::New => query.then_order_by(comment::published.desc()),
422       CommentSortType::Old => query.then_order_by(comment::published.asc()),
423       CommentSortType::Top => query.order_by(comment_aggregates::score.desc()),
424     };
425
426     // Note: deleted and removed comments are done on the front side
427     let res = query
428       .limit(limit)
429       .offset(offset)
430       .load::<CommentViewTuple>(self.conn)?;
431
432     Ok(CommentView::from_tuple_to_vec(res))
433   }
434 }
435
436 impl ViewToVec for CommentView {
437   type DbTuple = CommentViewTuple;
438   fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
439     items
440       .iter()
441       .map(|a| Self {
442         comment: a.0.to_owned(),
443         creator: a.1.to_owned(),
444         post: a.2.to_owned(),
445         community: a.3.to_owned(),
446         counts: a.4.to_owned(),
447         creator_banned_from_community: a.5.is_some(),
448         subscribed: CommunityFollower::to_subscribed_type(&a.6),
449         saved: a.7.is_some(),
450         creator_blocked: a.8.is_some(),
451         my_vote: a.9,
452       })
453       .collect::<Vec<Self>>()
454   }
455 }
456
457 #[cfg(test)]
458 mod tests {
459   use crate::comment_view::*;
460   use lemmy_db_schema::{
461     aggregates::structs::CommentAggregates,
462     source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*},
463     traits::{Blockable, Crud, Likeable},
464     utils::establish_unpooled_connection,
465     SubscribedType,
466   };
467   use serial_test::serial;
468
469   #[test]
470   #[serial]
471   fn test_crud() {
472     let conn = establish_unpooled_connection();
473
474     let new_person = PersonForm {
475       name: "timmy".into(),
476       public_key: Some("pubkey".to_string()),
477       ..PersonForm::default()
478     };
479
480     let inserted_person = Person::create(&conn, &new_person).unwrap();
481
482     let new_person_2 = PersonForm {
483       name: "sara".into(),
484       public_key: Some("pubkey".to_string()),
485       ..PersonForm::default()
486     };
487
488     let inserted_person_2 = Person::create(&conn, &new_person_2).unwrap();
489
490     let new_community = CommunityForm {
491       name: "test community 5".to_string(),
492       title: "nada".to_owned(),
493       public_key: Some("pubkey".to_string()),
494       ..CommunityForm::default()
495     };
496
497     let inserted_community = Community::create(&conn, &new_community).unwrap();
498
499     let new_post = PostForm {
500       name: "A test post 2".into(),
501       creator_id: inserted_person.id,
502       community_id: inserted_community.id,
503       ..PostForm::default()
504     };
505
506     let inserted_post = Post::create(&conn, &new_post).unwrap();
507
508     // Create a comment tree with this hierarchy
509     //       0
510     //     \     \
511     //    1      2
512     //    \
513     //  3  4
514     //     \
515     //     5
516     let comment_form_0 = CommentForm {
517       content: "Comment 0".into(),
518       creator_id: inserted_person.id,
519       post_id: inserted_post.id,
520       ..CommentForm::default()
521     };
522
523     let inserted_comment_0 = Comment::create(&conn, &comment_form_0, None).unwrap();
524
525     let comment_form_1 = CommentForm {
526       content: "Comment 1, A test blocked comment".into(),
527       creator_id: inserted_person_2.id,
528       post_id: inserted_post.id,
529       ..CommentForm::default()
530     };
531
532     let inserted_comment_1 =
533       Comment::create(&conn, &comment_form_1, Some(&inserted_comment_0.path)).unwrap();
534
535     let comment_form_2 = CommentForm {
536       content: "Comment 2".into(),
537       creator_id: inserted_person.id,
538       post_id: inserted_post.id,
539       ..CommentForm::default()
540     };
541
542     let inserted_comment_2 =
543       Comment::create(&conn, &comment_form_2, Some(&inserted_comment_0.path)).unwrap();
544
545     let comment_form_3 = CommentForm {
546       content: "Comment 3".into(),
547       creator_id: inserted_person.id,
548       post_id: inserted_post.id,
549       ..CommentForm::default()
550     };
551
552     let _inserted_comment_3 =
553       Comment::create(&conn, &comment_form_3, Some(&inserted_comment_1.path)).unwrap();
554
555     let comment_form_4 = CommentForm {
556       content: "Comment 4".into(),
557       creator_id: inserted_person.id,
558       post_id: inserted_post.id,
559       ..CommentForm::default()
560     };
561
562     let inserted_comment_4 =
563       Comment::create(&conn, &comment_form_4, Some(&inserted_comment_1.path)).unwrap();
564
565     let comment_form_5 = CommentForm {
566       content: "Comment 5".into(),
567       creator_id: inserted_person.id,
568       post_id: inserted_post.id,
569       ..CommentForm::default()
570     };
571
572     let _inserted_comment_5 =
573       Comment::create(&conn, &comment_form_5, Some(&inserted_comment_4.path)).unwrap();
574
575     let timmy_blocks_sara_form = PersonBlockForm {
576       person_id: inserted_person.id,
577       target_id: inserted_person_2.id,
578     };
579
580     let inserted_block = PersonBlock::block(&conn, &timmy_blocks_sara_form).unwrap();
581
582     let expected_block = PersonBlock {
583       id: inserted_block.id,
584       person_id: inserted_person.id,
585       target_id: inserted_person_2.id,
586       published: inserted_block.published,
587     };
588
589     assert_eq!(expected_block, inserted_block);
590
591     let comment_like_form = CommentLikeForm {
592       comment_id: inserted_comment_0.id,
593       post_id: inserted_post.id,
594       person_id: inserted_person.id,
595       score: 1,
596     };
597
598     let _inserted_comment_like = CommentLike::like(&conn, &comment_like_form).unwrap();
599
600     let agg = CommentAggregates::read(&conn, inserted_comment_0.id).unwrap();
601
602     let top_path = inserted_comment_0.to_owned().path;
603     let expected_comment_view_no_person = CommentView {
604       creator_banned_from_community: false,
605       my_vote: None,
606       subscribed: SubscribedType::NotSubscribed,
607       saved: false,
608       creator_blocked: false,
609       comment: Comment {
610         id: inserted_comment_0.id,
611         content: "Comment 0".into(),
612         creator_id: inserted_person.id,
613         post_id: inserted_post.id,
614         removed: false,
615         deleted: false,
616         published: inserted_comment_0.published,
617         ap_id: inserted_comment_0.ap_id,
618         updated: None,
619         local: true,
620         path: top_path,
621       },
622       creator: PersonSafe {
623         id: inserted_person.id,
624         name: "timmy".into(),
625         display_name: None,
626         published: inserted_person.published,
627         avatar: None,
628         actor_id: inserted_person.actor_id.to_owned(),
629         local: true,
630         banned: false,
631         deleted: false,
632         admin: false,
633         bot_account: false,
634         bio: None,
635         banner: None,
636         updated: None,
637         inbox_url: inserted_person.inbox_url.to_owned(),
638         shared_inbox_url: None,
639         matrix_user_id: None,
640         ban_expires: None,
641       },
642       post: Post {
643         id: inserted_post.id,
644         name: inserted_post.name.to_owned(),
645         creator_id: inserted_person.id,
646         url: None,
647         body: None,
648         published: inserted_post.published,
649         updated: None,
650         community_id: inserted_community.id,
651         removed: false,
652         deleted: false,
653         locked: false,
654         stickied: false,
655         nsfw: false,
656         embed_title: None,
657         embed_description: None,
658         embed_video_url: None,
659         thumbnail_url: None,
660         ap_id: inserted_post.ap_id.to_owned(),
661         local: true,
662       },
663       community: CommunitySafe {
664         id: inserted_community.id,
665         name: "test community 5".to_string(),
666         icon: None,
667         removed: false,
668         deleted: false,
669         nsfw: false,
670         actor_id: inserted_community.actor_id.to_owned(),
671         local: true,
672         title: "nada".to_owned(),
673         description: None,
674         updated: None,
675         banner: None,
676         hidden: false,
677         posting_restricted_to_mods: false,
678         published: inserted_community.published,
679       },
680       counts: CommentAggregates {
681         id: agg.id,
682         comment_id: inserted_comment_0.id,
683         score: 1,
684         upvotes: 1,
685         downvotes: 0,
686         published: agg.published,
687         child_count: 5,
688       },
689     };
690
691     let mut expected_comment_view_with_person = expected_comment_view_no_person.to_owned();
692     expected_comment_view_with_person.my_vote = Some(1);
693
694     let read_comment_views_no_person = CommentQueryBuilder::create(&conn)
695       .post_id(inserted_post.id)
696       .list()
697       .unwrap();
698
699     assert_eq!(
700       expected_comment_view_no_person,
701       read_comment_views_no_person[0]
702     );
703
704     let read_comment_views_with_person = CommentQueryBuilder::create(&conn)
705       .post_id(inserted_post.id)
706       .my_person_id(inserted_person.id)
707       .list()
708       .unwrap();
709
710     assert_eq!(
711       expected_comment_view_with_person,
712       read_comment_views_with_person[0]
713     );
714
715     // Make sure its 1, not showing the blocked comment
716     assert_eq!(5, read_comment_views_with_person.len());
717
718     let read_comment_from_blocked_person =
719       CommentView::read(&conn, inserted_comment_1.id, Some(inserted_person.id)).unwrap();
720
721     // Make sure block set the creator blocked
722     assert!(read_comment_from_blocked_person.creator_blocked);
723
724     let top_path = inserted_comment_0.path;
725     let read_comment_views_top_path = CommentQueryBuilder::create(&conn)
726       .post_id(inserted_post.id)
727       .parent_path(top_path)
728       .list()
729       .unwrap();
730
731     let child_path = inserted_comment_1.to_owned().path;
732     let read_comment_views_child_path = CommentQueryBuilder::create(&conn)
733       .post_id(inserted_post.id)
734       .parent_path(child_path)
735       .list()
736       .unwrap();
737
738     // Make sure the comment parent-limited fetch is correct
739     assert_eq!(6, read_comment_views_top_path.len());
740     assert_eq!(4, read_comment_views_child_path.len());
741
742     // Make sure it contains the parent, but not the comment from the other tree
743     let child_comments = read_comment_views_child_path
744       .into_iter()
745       .map(|c| c.comment)
746       .collect::<Vec<Comment>>();
747     assert!(child_comments.contains(&inserted_comment_1));
748     assert!(!child_comments.contains(&inserted_comment_2));
749
750     let read_comment_views_top_max_depth = CommentQueryBuilder::create(&conn)
751       .post_id(inserted_post.id)
752       .max_depth(1)
753       .list()
754       .unwrap();
755
756     // Make sure a depth limited one only has the top comment
757     assert_eq!(
758       expected_comment_view_no_person,
759       read_comment_views_top_max_depth[0]
760     );
761     assert_eq!(1, read_comment_views_top_max_depth.len());
762
763     let child_path = inserted_comment_1.path;
764     let read_comment_views_parent_max_depth = CommentQueryBuilder::create(&conn)
765       .post_id(inserted_post.id)
766       .parent_path(child_path)
767       .max_depth(1)
768       .sort(CommentSortType::New)
769       .list()
770       .unwrap();
771
772     // Make sure a depth limited one, and given child comment 1, has 3
773     assert!(read_comment_views_parent_max_depth[2]
774       .comment
775       .content
776       .eq("Comment 3"));
777     assert_eq!(3, read_comment_views_parent_max_depth.len());
778
779     // Delete everything
780     let like_removed =
781       CommentLike::remove(&conn, inserted_person.id, inserted_comment_0.id).unwrap();
782     let num_deleted = Comment::delete(&conn, inserted_comment_0.id).unwrap();
783     Comment::delete(&conn, inserted_comment_1.id).unwrap();
784     Post::delete(&conn, inserted_post.id).unwrap();
785     Community::delete(&conn, inserted_community.id).unwrap();
786     Person::delete(&conn, inserted_person.id).unwrap();
787     Person::delete(&conn, inserted_person_2.id).unwrap();
788
789     assert_eq!(1, num_deleted);
790     assert_eq!(1, like_removed);
791   }
792 }