From a14bddb39e106ec3dfaabd8d817deb6bdcac6507 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 23 Apr 2021 12:10:16 -0700 Subject: [PATCH] Separate modeling queries into public vs user data This will enable better caching! Though it looks like the stale-while-revalidate isn't coming through on modeling public data, I wonder why? --- src/app/ModelingPage.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/app/ModelingPage.js b/src/app/ModelingPage.js index 84f95dc..bda99cd 100644 --- a/src/app/ModelingPage.js +++ b/src/app/ModelingPage.js @@ -12,6 +12,7 @@ import ItemCard, { NcBadge, YouOwnThisBadge, } from "./components/ItemCard"; +import useCurrentUser from "./components/useCurrentUser"; function ModelingPage() { usePageTitle("Modeling Hub"); @@ -25,6 +26,8 @@ function ModelingPage() { } function ItemModelsSection() { + const { isLoggedIn } = useCurrentUser(); + const { loading, error, data } = useQuery( gql` query ModelingPage { @@ -59,12 +62,6 @@ function ItemModelsSection() { name } } - - currentUser { - itemsTheyOwn { - id - } - } } fragment ItemFields on Item { @@ -74,8 +71,23 @@ function ItemModelsSection() { isNc createdAt } + ` + ); + + // We're going to be silent about the loading/error states here, because it's + // not essential info anyway, and announcing the wait or the failure would be + // more confusing than anything. + const { data: userData } = useQuery( + gql` + query ModelingPage_UserData { + currentUser { + itemsTheyOwn { + id + } + } + } `, - { context: { sendAuth: true } } + { context: { sendAuth: true }, skip: !isLoggedIn } ); if (loading) { @@ -102,7 +114,7 @@ function ItemModelsSection() { } const ownedItemIds = new Set( - data.currentUser?.itemsTheyOwn?.map((item) => item.id) + userData?.currentUser?.itemsTheyOwn?.map((item) => item.id) ); return (