From 41b49c5d3624904f18f8c080335c6c09388c3c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=BD=D0=BE=D0=B9=20=D0=B8=D1=88?= =?UTF-8?q?=D0=B0=D0=BA?= <69521267+undrcrxwn@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:28:27 +0300 Subject: [PATCH] fix(comments): prevent comment duplicates in Cypher queries --- .../Services/CommentRepository.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CrowdParlay.Social.Infrastructure.Persistence/Services/CommentRepository.cs b/src/CrowdParlay.Social.Infrastructure.Persistence/Services/CommentRepository.cs index f6df541..497d6eb 100644 --- a/src/CrowdParlay.Social.Infrastructure.Persistence/Services/CommentRepository.cs +++ b/src/CrowdParlay.Social.Infrastructure.Persistence/Services/CommentRepository.cs @@ -19,7 +19,7 @@ public async Task 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, @@ -72,7 +72,7 @@ public async Task> 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, @@ -131,7 +131,7 @@ public async Task> 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) @@ -139,7 +139,7 @@ public async Task> GetRepliesToCommentAsync(Guid parentC .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, @@ -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,