From 7b0ce0c31b334e940a2faff009ba5bf84e8c32a4 Mon Sep 17 00:00:00 2001 From: keyan Date: Fri, 4 Mar 2022 12:05:16 -0600 Subject: [PATCH] don't be an idiot and fetch comments when we don't need them --- api/resolvers/item.js | 6 +++--- fragments/users.js | 8 -------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 7a2cc7b1..1a956187 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -43,9 +43,6 @@ export async function getItem (parent, { id }, { models }) { ${SELECT} FROM "Item" WHERE id = $1`, Number(id)) - if (item) { - item.comments = comments(models, id, 'hot') - } return item } @@ -676,6 +673,9 @@ export default { WHERE path <@ text2ltree(${item.path}) AND id != ${Number(item.id)}` return count || 0 }, + comments: async (item, args, { models }) => { + return comments(models, item.id, 'hot') + }, sats: async (item, args, { models }) => { const { sum: { sats } } = await models.itemAct.aggregate({ sum: { diff --git a/fragments/users.js b/fragments/users.js index 6d8a1abb..feb1f8e6 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -64,14 +64,10 @@ export const USER_FULL = gql` export const USER_WITH_COMMENTS = gql` ${USER_FIELDS} - ${ITEM_WITH_COMMENTS} ${COMMENT_FIELDS} query UserWithComments($name: String!) { user(name: $name) { ...UserFields - bio { - ...ItemWithComments - } } moreFlatComments(sort: "user", name: $name) { cursor @@ -83,14 +79,10 @@ export const USER_WITH_COMMENTS = gql` export const USER_WITH_POSTS = gql` ${USER_FIELDS} - ${ITEM_WITH_COMMENTS} ${ITEM_FIELDS} query UserWithPosts($name: String!) { user(name: $name) { ...UserFields - bio { - ...ItemWithComments - } } items(sort: "user", name: $name) { cursor