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:
parent
b73e2e1123
commit
b941dce9fa
1 changed files with 16 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue