Skip to content

Commit

Permalink
#20 I think it was an index issue, but turns out don't need an index
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroves committed Sep 25, 2023
1 parent df02989 commit 3bef149
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
33 changes: 0 additions & 33 deletions Conduit/Conduit.Migrations/009_CreateIndexForGetComments.cs

This file was deleted.

9 changes: 5 additions & 4 deletions Conduit/Conduit.Web/Articles/Services/CommentsDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public async Task<DataServiceResult<List<CommentListDataView>>> Get(string slug,
var bucket = scope.Bucket;

var loggedInJoin = "";
var loggedInProjection = " \"following\" : false ";
if (currentUsername != null)
{
loggedInProjection = $" \"following\": ARRAY_CONTAINS(COALESCE(follow,[]), c.authorUsername) ";
loggedInJoin = $" LEFT JOIN `{bucket.Name}`.`{scope.Name}`.`Follows` follow ON ($currentUsername || \"::follows\") = META(follow).id ";
}

Expand All @@ -73,17 +75,16 @@ public async Task<DataServiceResult<List<CommentListDataView>>> Get(string slug,
author.bio,
author.image,
""username"": c.authorUsername,
""following"": ARRAY_CONTAINS(COALESCE(follow,[]), c.authorUsername)
{loggedInProjection}
}}
}}
FROM {bucket.Name}.`{scope.Name}`.`Comments` c2
USE KEYS $commentsKey
UNNEST c2 AS c
JOIN `{bucket.Name}`.`{scope.Name}`.`Users` author ON c.authorUsername = META(author).id
{loggedInJoin}
WHERE META(c2).id = $commentsKey;";
{loggedInJoin} ;";

var cluster = collection.Scope.Bucket.Cluster;
// try
Expand Down
2 changes: 1 addition & 1 deletion Conduit/Conduit.Web/DataAccess/Queries/GetComments.n1qlnb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells":[{"kind":2,"language":"SQL++","value":"SELECT VALUE\r\n {\r\n c.body,\r\n c.createdAt,\r\n c.id,\r\n \"author\" : {\r\n author.bio,\r\n author.image,\r\n \"username\": c.authorUsername,\r\n \"following\": ARRAY_CONTAINS(COALESCE(follow,[]), c.authorUsername)\r\n }\r\n }\r\n\r\nFROM Conduit._default.Comments c2\r\nUNNEST c2 AS c\r\nJOIN Conduit._default.Users author ON c.authorUsername = META(author).id\r\n\r\n/* join to the logged in user if not anonymous */\r\n/* parameterized with logged in username */\r\nLEFT JOIN Conduit._default.Follows follow ON (\"mgroves\" || \"::follows\") = META(follow).id\r\n\r\n/* parameterized with comments key */\r\nWHERE META(c2).id = \"HLbwIpJEajZi::comments\";\r\n"}]}
{"cells":[{"kind":2,"language":"SQL++","value":"SELECT VALUE\r\n {\r\n c.body,\r\n c.createdAt,\r\n c.id,\r\n \"author\" : {\r\n author.bio,\r\n author.image,\r\n \"username\": c.authorUsername,\r\n \"following\": ARRAY_CONTAINS(COALESCE(follow,[]), c.authorUsername)\r\n }\r\n }\r\n\r\nFROM Conduit._default.Comments c2\r\nUSE KEYS \"OjeIfc7nudAW::comments\"\r\nUNNEST c2 AS c\r\nJOIN Conduit._default.Users author ON c.authorUsername = META(author).id\r\n\r\n/* join to the logged in user if not anonymous */\r\n/* parameterized with logged in username */\r\nLEFT JOIN Conduit._default.Follows follow ON (\"mgroves\" || \"::follows\") = META(follow).id\r\n\r\n\r\n"}]}

0 comments on commit 3bef149

Please sign in to comment.