mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
add test case
This commit is contained in:
parent
88703a909c
commit
3f8c998170
3 changed files with 29 additions and 2 deletions
|
@ -858,3 +858,29 @@ test("Dont send a comment reply to a blocked community", async () => {
|
|||
blockRes = await blockCommunity(beta, newCommunityId, false);
|
||||
expect(blockRes.blocked).toBe(false);
|
||||
});
|
||||
|
||||
/// Fetching a deeply nested comment can lead to stack overflow as all parent comments are also
|
||||
/// fetched recursively. Ensure that it works properly.
|
||||
test("Fetch a deeply nested comment", async () => {
|
||||
let lastComment;
|
||||
for (let i = 0; i < 100; i++) {
|
||||
let parent_id = lastComment?.comment_view.comment.id;
|
||||
|
||||
let commentRes = await createComment(
|
||||
alpha,
|
||||
postOnAlphaRes.post_view.post.id,
|
||||
parent_id,
|
||||
);
|
||||
expect(commentRes.comment_view.comment).toBeDefined();
|
||||
lastComment = commentRes;
|
||||
}
|
||||
|
||||
let betaComment = await resolveComment(
|
||||
beta,
|
||||
lastComment!.comment_view.comment,
|
||||
);
|
||||
|
||||
console.log(betaComment!.comment!.comment.path);
|
||||
expect(betaComment!.comment!.comment).toBeDefined();
|
||||
expect(betaComment?.comment?.post).toBeDefined();
|
||||
});
|
||||
|
|
|
@ -136,6 +136,8 @@ impl Object for ApubComment {
|
|||
Ok(note)
|
||||
}
|
||||
|
||||
/// Recursively fetches all parent comments. This can lead to a stack overflow so we need to
|
||||
/// Box::pin all large futures on the heap.
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn verify(
|
||||
note: &Note,
|
||||
|
@ -163,7 +165,7 @@ impl Object for ApubComment {
|
|||
|
||||
let (post, _) = Box::pin(note.get_parents(context)).await?;
|
||||
let creator = Box::pin(note.attributed_to.dereference(context)).await?;
|
||||
let is_mod_or_admin = Box::pin(is_mod_or_admin(&mut context.pool(), &creator, community.id))
|
||||
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &creator, community.id)
|
||||
.await
|
||||
.is_ok();
|
||||
if post.locked && !is_mod_or_admin {
|
||||
|
|
|
@ -23,7 +23,6 @@ use lemmy_db_schema::{
|
|||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use std::ops::Deref;
|
||||
use url::Url;
|
||||
|
||||
#[skip_serializing_none]
|
||||
|
|
Loading…
Reference in a new issue