Private cache headers in item search

If the user is searching for things they own or want, make sure we don't CDN cache it!

For many queries, this is taken care of in practice, because the search result includes `currentUserOwnsThis` and `currentUserWantsThis`. But I noticed in testing that, if the search result has no items, so those fields aren't actually part of the _response_, then the private header doesn't get set. So this mainly makes sure we don't accidentally cache an empty result from a user who didn't have anything they owned/wanted yet!
This commit is contained in:
Emi Matchu 2021-11-16 13:09:45 -08:00
parent b73e2e1123
commit b941dce9fa

View file

@ -656,8 +656,13 @@ const resolvers = {
itemSearchItemsLoader,
petTypeBySpeciesAndColorLoader,
currentUserId,
}
},
{ cacheControl }
) => {
if (currentUserOwnsOrWants != null) {
cacheControl.setCacheHint({ scope: "PRIVATE" });
}
let bodyId = null;
if (fitsPet) {
const petType = await petTypeBySpeciesAndColorLoader.load({
@ -790,8 +795,12 @@ const resolvers = {
numTotalItems: async (
{ query, bodyId, itemKind, currentUserOwnsOrWants, zoneIds },
{ offset, limit },
{ currentUserId, itemSearchNumTotalItemsLoader }
{ currentUserId, itemSearchNumTotalItemsLoader },
{ cacheControl }
) => {
if (currentUserOwnsOrWants != null) {
cacheControl.setCacheHint({ scope: "PRIVATE" });
}
const numTotalItems = await itemSearchNumTotalItemsLoader.load({
query: query.trim(),
bodyId,
@ -807,8 +816,12 @@ const resolvers = {
items: async (
{ query, bodyId, itemKind, currentUserOwnsOrWants, zoneIds },
{ offset, limit },
{ currentUserId, itemSearchItemsLoader }
{ currentUserId, itemSearchItemsLoader },
{ cacheControl }
) => {
if (currentUserOwnsOrWants != null) {
cacheControl.setCacheHint({ scope: "PRIVATE" });
}
const items = await itemSearchItemsLoader.load({
query: query.trim(),
bodyId,