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:
parent
a0be9942fb
commit
277b8df838
1 changed files with 23 additions and 2 deletions
|
@ -379,12 +379,26 @@ function NewItemsSectionContent() {
|
||||||
thumbnailUrl
|
thumbnailUrl
|
||||||
isNc
|
isNc
|
||||||
isPb
|
isPb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: userData } = useQuery(
|
||||||
|
gql`
|
||||||
|
query NewItemsSection_UserData {
|
||||||
|
newestItems {
|
||||||
|
id
|
||||||
currentUserOwnsThis
|
currentUserOwnsThis
|
||||||
currentUserWantsThis
|
currentUserWantsThis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
{ context: { sendAuth: true } }
|
{
|
||||||
|
context: { sendAuth: true },
|
||||||
|
onError: (e) =>
|
||||||
|
console.error("Error loading NewItemsSection_UserData, skipping:", e),
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loading) {
|
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 (
|
return (
|
||||||
<ItemCardHStack>
|
<ItemCardHStack>
|
||||||
{data.newestItems.map((item) => (
|
{newestItems.map((item) => (
|
||||||
<SquareItemCard key={item.id} item={item} />
|
<SquareItemCard key={item.id} item={item} />
|
||||||
))}
|
))}
|
||||||
</ItemCardHStack>
|
</ItemCardHStack>
|
||||||
|
|
Loading…
Reference in a new issue