-
-
Save undrcrxwn/8d4237a7c531084abbd7f303e5a41b00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = await query | |
.Match(matchSelector) | |
.With("COLLECT(author) AS authors, COLLECT(comment) AS comments, COUNT(comment) AS totalCount") | |
.Unwind("authors", "author") | |
.Unwind("comments", "comment") | |
.With("author, comment, totalCount") | |
.OrderBy("comment.CreatedAt") | |
.Skip(offset) | |
.Limit(count) | |
.OptionalMatch("(replyAuthor:Author)<-[:AUTHORED_BY]-(reply:Comment)-[:REPLIES_TO]->(comment)") | |
.OptionalMatch("(indirectReply:Comment)-[:REPLIES_TO*]->(reply)") | |
.With( | |
""" | |
totalCount, comment, author, COUNT(reply) + COUNT(indirectReply) AS replyCount, | |
CASE WHEN COUNT(reply) > 0 THEN COLLECT(DISTINCT { | |
Id: replyAuthor.Id, | |
Username: replyAuthor.Username, | |
DisplayName: replyAuthor.DisplayName, | |
AvatarUrl: replyAuthor.AvatarUrl | |
})[0..3] ELSE [] END AS firstRepliesAuthors | |
""") | |
.With( | |
""" | |
{ | |
Id: comment.Id, | |
Content: comment.Content, | |
Author: { | |
Id: author.Id, | |
Username: author.Username, | |
DisplayName: author.DisplayName, | |
AvatarUrl: author.AvatarUrl | |
}, | |
CreatedAt: datetime(comment.CreatedAt), | |
ReplyCount: replyCount, | |
FirstRepliesAuthors: firstRepliesAuthors | |
} | |
AS comment, totalCount | |
""") | |
.Return((comment, totalCount) => new Page<CommentDto> | |
{ | |
TotalCount = totalCount.As<int>(), | |
Items = comment.CollectAs<CommentDto>() | |
}) | |
.ResultsAsync; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment