Fix caching for homepage Latest Items

Oh right, adding user data to this query makes it uncacheable!

Split the query into the main public data, which will cache; and the user data, which will load in later.
This commit is contained in:
Emi Matchu 2021-06-08 01:59:56 -07:00
parent a0be9942fb
commit 277b8df838

View file

@ -379,12 +379,26 @@ function NewItemsSectionContent() {
thumbnailUrl
isNc
isPb
}
}
`
);
const { data: userData } = useQuery(
gql`
query NewItemsSection_UserData {
newestItems {
id
currentUserOwnsThis
currentUserWantsThis
}
}
`,
{ context: { sendAuth: true } }
{
context: { sendAuth: true },
onError: (e) =>
console.error("Error loading NewItemsSection_UserData, skipping:", e),
}
);
if (loading) {
@ -424,9 +438,16 @@ function NewItemsSectionContent() {
);
}
// Merge in the results from the user data query, if available.
const newestItems = data.newestItems.map((item) => {
const itemUserData =
(userData?.newestItems || []).find((i) => i.id === item.id) || {};
return { ...item, ...itemUserData };
});
return (
<ItemCardHStack>
{data.newestItems.map((item) => (
{newestItems.map((item) => (
<SquareItemCard key={item.id} item={item} />
))}
</ItemCardHStack>