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?
This commit is contained in:
Emi Matchu 2021-04-23 12:10:16 -07:00
parent 2f7b6571f2
commit a14bddb39e

View file

@ -12,6 +12,7 @@ import ItemCard, {
NcBadge, NcBadge,
YouOwnThisBadge, YouOwnThisBadge,
} from "./components/ItemCard"; } from "./components/ItemCard";
import useCurrentUser from "./components/useCurrentUser";
function ModelingPage() { function ModelingPage() {
usePageTitle("Modeling Hub"); usePageTitle("Modeling Hub");
@ -25,6 +26,8 @@ function ModelingPage() {
} }
function ItemModelsSection() { function ItemModelsSection() {
const { isLoggedIn } = useCurrentUser();
const { loading, error, data } = useQuery( const { loading, error, data } = useQuery(
gql` gql`
query ModelingPage { query ModelingPage {
@ -59,12 +62,6 @@ function ItemModelsSection() {
name name
} }
} }
currentUser {
itemsTheyOwn {
id
}
}
} }
fragment ItemFields on Item { fragment ItemFields on Item {
@ -74,8 +71,23 @@ function ItemModelsSection() {
isNc isNc
createdAt 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) { if (loading) {
@ -102,7 +114,7 @@ function ItemModelsSection() {
} }
const ownedItemIds = new Set( const ownedItemIds = new Set(
data.currentUser?.itemsTheyOwn?.map((item) => item.id) userData?.currentUser?.itemsTheyOwn?.map((item) => item.id)
); );
return ( return (