diff --git a/api/models/index.js b/api/models/index.js
index 1312709e..e79851f2 100644
--- a/api/models/index.js
+++ b/api/models/index.js
@@ -1,7 +1,7 @@
import { PrismaClient } from '@prisma/client'
const prisma = global.prisma || new PrismaClient({
- log: ['query', 'warn', 'error']
+ log: ['warn', 'error']
})
if (process.env.NODE_ENV === 'development') global.prisma = prisma
diff --git a/api/resolvers/notifications.js b/api/resolvers/notifications.js
index 138b9146..eac7a6bb 100644
--- a/api/resolvers/notifications.js
+++ b/api/resolvers/notifications.js
@@ -1,3 +1,4 @@
+import { AuthenticationError } from 'apollo-server-micro'
import { decodeCursor, LIMIT, nextCursorEncoded } from './cursor'
export default {
@@ -44,7 +45,8 @@ export default {
let notifications = await models.$queryRaw(`
SELECT ${ITEM_FIELDS}, "Item".created_at as sort_time, NULL as "earnedSats"
From "Item"
- JOIN "Item" p ON "Item"."parentId" = p.id AND p."userId" = $1
+ JOIN "Item" p ON "Item"."parentId" = p.id
+ WHERE p."userId" = $1
AND "Item"."userId" <> $1 AND "Item".created_at <= $2
UNION ALL
(SELECT ${ITEM_SUBQUERY_FIELDS}, max(subquery.voted_at) as sort_time, sum(subquery.sats) as "earnedSats"
@@ -52,16 +54,16 @@ export default {
(SELECT ${ITEM_FIELDS}, "Vote".created_at as voted_at, "Vote".sats,
ROW_NUMBER() OVER(ORDER BY "Vote".created_at) -
ROW_NUMBER() OVER(PARTITION BY "Item".id ORDER BY "Vote".created_at) as island
- FROM "Item"
- LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id
- AND "Vote"."userId" <> $1
+ FROM "Vote"
+ JOIN "Item" on "Vote"."itemId" = "Item".id
+ WHERE "Vote"."userId" <> $1
AND "Item".created_at <= $2
AND "Vote".boost = false
- WHERE "Item"."userId" = $1) subquery
+ AND "Item"."userId" = $1) subquery
GROUP BY ${ITEM_SUBQUERY_FIELDS}, subquery.island ORDER BY max(subquery.voted_at) desc)
ORDER BY sort_time DESC
OFFSET $3
- LIMIT ${LIMIT}`, me ? me.id : 622, decodedCursor.time, decodedCursor.offset)
+ LIMIT ${LIMIT}`, 622, decodedCursor.time, decodedCursor.offset)
notifications = notifications.map(n => {
n.item = { ...n }
@@ -85,4 +87,4 @@ const ITEM_SUBQUERY_FIELDS =
const ITEM_FIELDS =
`"Item".id, "Item".created_at as "createdAt", "Item".updated_at as "updatedAt", "Item".title,
- "Item".text, "Item".url, "Item"."userId", "Item"."parentId", ltree2text("Item"."path") AS "path"`
+ "Item".text, "Item".url, "Item"."userId", "Item"."parentId", ltree2text("Item"."path") AS path`
diff --git a/api/resolvers/user.js b/api/resolvers/user.js
index 9a198482..92f84d13 100644
--- a/api/resolvers/user.js
+++ b/api/resolvers/user.js
@@ -25,12 +25,12 @@ export default {
const [{ sum }] = await models.$queryRaw(`
SELECT sum("Vote".sats)
- FROM "Item"
- LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id
- AND "Vote"."userId" <> $1
+ FROM "Vote"
+ JOIN "Item" on "Vote"."itemId" = "Item".id
+ WHERE "Vote"."userId" <> $1
AND ("Vote".created_at > $2 OR $2 IS NULL)
AND "Vote".boost = false
- WHERE "Item"."userId" = $1`, user.id, user.checkedNotesAt)
+ AND "Item"."userId" = $1`, user.id, user.checkedNotesAt)
await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } })
return sum || 0
@@ -64,9 +64,10 @@ export default {
stacked: async (user, args, { models }) => {
const [{ sum }] = await models.$queryRaw`
SELECT sum("Vote".sats)
- FROM "Item"
- LEFT JOIN "Vote" on "Vote"."itemId" = "Item".id AND "Vote"."userId" <> ${user.id} AND boost = false
- WHERE "Item"."userId" = ${user.id}`
+ FROM "Vote"
+ JOIN "Item" on "Vote"."itemId" = "Item".id
+ WHERE "Vote"."userId" <> ${user.id} AND boost = false
+ AND "Item"."userId" = ${user.id}`
return sum || 0
},
sats: async (user, args, { models }) => {
@@ -77,11 +78,11 @@ export default {
const votes = await models.$queryRaw(`
SELECT "Vote".id, "Vote".created_at
FROM "Vote"
- LEFT JOIN "Item" on "Vote"."itemId" = "Item".id
- AND "Vote"."userId" <> $1
+ JOIN "Item" on "Vote"."itemId" = "Item".id
+ WHERE "Vote"."userId" <> $1
AND ("Vote".created_at > $2 OR $2 IS NULL)
AND "Vote".boost = false
- WHERE "Item"."userId" = $1
+ AND "Item"."userId" = $1
LIMIT 1`, user.id, user.checkedNotesAt)
if (votes.length > 0) {
return true
@@ -91,7 +92,8 @@ export default {
const newReplies = await models.$queryRaw(`
SELECT "Item".id, "Item".created_at
From "Item"
- JOIN "Item" p ON "Item"."parentId" = p.id AND p."userId" = $1
+ JOIN "Item" p ON "Item"."parentId" = p.id
+ WHERE p."userId" = $1
AND ("Item".created_at > $2 OR $2 IS NULL) AND "Item"."userId" <> $1
LIMIT 1`, user.id, user.checkedNotesAt)
return !!newReplies.length
diff --git a/api/typeDefs/item.js b/api/typeDefs/item.js
index 99a4f111..c01a8378 100644
--- a/api/typeDefs/item.js
+++ b/api/typeDefs/item.js
@@ -44,5 +44,6 @@ export default gql`
meSats: Int!
ncomments: Int!
comments: [Item!]!
+ path: String
}
`
diff --git a/components/comment.js b/components/comment.js
index edd58068..5620cb2b 100644
--- a/components/comment.js
+++ b/components/comment.js
@@ -13,7 +13,7 @@ import { useMe } from './me'
import CommentEdit from './comment-edit'
import Countdown from './countdown'
-function Parent ({ item }) {
+function Parent ({ item, rootText }) {
const ParentFrag = () => (
<>
\
@@ -32,13 +32,13 @@ function Parent ({ item }) {
{Number(item.root.id) !== Number(item.parentId) &&