Skip to content

Commit

Permalink
fix(comments): prevent comment duplicates in Cypher queries
Browse files Browse the repository at this point in the history
  • Loading branch information
undrcrxwn committed Feb 10, 2024
1 parent 9a5957e commit 41b49c5
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<CommentDto> GetByIdAsync(Guid id)
.OptionalMatch("(replyAuthor:Author)<-[:AUTHORED_BY]-(reply:Comment)-[:REPLIES_TO]->(comment)")
.With(
"""
*, COUNT(reply) AS replyCount,
comment, author, COUNT(reply) AS replyCount,
CASE WHEN COUNT(reply) > 0 THEN COLLECT(DISTINCT {
Id: replyAuthor.Id,
Username: replyAuthor.Username,
Expand Down Expand Up @@ -72,7 +72,7 @@ public async Task<IEnumerable<CommentDto>> SearchAsync(Guid? discussionId, Guid?
.OptionalMatch("(replyAuthor:Author)<-[:AUTHORED_BY]-(reply:Comment)-[:REPLIES_TO]->(comment)")
.With(
"""
*, COUNT(reply) AS replyCount,
comment, author, COUNT(reply) AS replyCount,
CASE WHEN COUNT(reply) > 0 THEN COLLECT(DISTINCT {
Id: replyAuthor.Id,
Username: replyAuthor.Username,
Expand Down Expand Up @@ -131,15 +131,15 @@ public async Task<IEnumerable<CommentDto>> GetRepliesToCommentAsync(Guid parentC
{
return await _graphClient.Cypher
.WithParams(new { parentCommentId })
.Match("(commentAuthor:Author)<-[:AUTHORED_BY]-(comment:Comment)-[:REPLIES_TO]->(parent:Comment { Id: $parentCommentId })")
.Match("(author:Author)<-[:AUTHORED_BY]-(comment:Comment)-[:REPLIES_TO]->(parent:Comment { Id: $parentCommentId })")
.With("*")
.OrderBy("comment.CreatedAt")
.Skip(page * size)
.Limit(size)
.OptionalMatch("(replyAuthor:Author)<-[:AUTHORED_BY]-(reply:Comment)-[:REPLIES_TO]->(comment)")
.With(
"""
*, COUNT(reply) AS replyCount,
comment, author, COUNT(reply) AS replyCount,
CASE WHEN COUNT(reply) > 0 THEN COLLECT(DISTINCT {
Id: replyAuthor.Id,
Username: replyAuthor.Username,
Expand All @@ -153,10 +153,10 @@ CASE WHEN COUNT(reply) > 0 THEN COLLECT(DISTINCT {
Id: comment.Id,
Content: comment.Content,
Author: {
Id: commentAuthor.Id,
Username: commentAuthor.Username,
DisplayName: commentAuthor.DisplayName,
AvatarUrl: commentAuthor.AvatarUrl
Id: author.Id,
Username: author.Username,
DisplayName: author.DisplayName,
AvatarUrl: author.AvatarUrl
},
CreatedAt: datetime(comment.CreatedAt),
ReplyCount: replyCount,
Expand Down

0 comments on commit 41b49c5

Please sign in to comment.