Skip to content

Commit

Permalink
chore: skip CDN for force.true requests
Browse files Browse the repository at this point in the history
  • Loading branch information
MounirDhahri committed Sep 25, 2024
1 parent da9963b commit 388a95d
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/app/Scenes/Articles/Articles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { useTracking } from "react-tracking"
import { ArticlesList, ArticlesPlaceholder } from "./ArticlesList"

export const Articles: React.FC = () => {
const queryData = useLazyLoadQuery<ArticlesQuery>(ArticlesScreenQuery, articlesQueryVariables)
const queryData = useLazyLoadQuery<ArticlesQuery>(ArticlesScreenQuery, articlesQueryVariables, {
networkCacheConfig: {
force: false,
},
})

const { data, loadNext, hasNext, isLoadingNext, refetch } = usePaginationFragment<
ArticlesQuery,
Expand Down
1 change: 1 addition & 0 deletions src/app/Scenes/Artist/Artist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export const ArtistQueryRenderer: React.FC<ArtistQueryRendererProps> = (props) =
`,
variables: { artistID },
}}
cacheConfig={{ force: false }}
render={{
renderPlaceholder: () => <ArtistSkeleton />,
renderComponent: ({ above, below }) => {
Expand Down
10 changes: 9 additions & 1 deletion src/app/Scenes/Collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ export const CollectionContent: React.FC<CollectionProps> = ({ collection }) =>
}

const CollectionQueryRenderer: React.FC<CollectionScreenProps> = ({ collectionID }) => {
const data = useLazyLoadQuery<CollectionQuery>(query, { collectionID })
const data = useLazyLoadQuery<CollectionQuery>(
query,
{ collectionID },
{
networkCacheConfig: {
force: false,
},
}
)

if (!data?.collection) {
return null
Expand Down
10 changes: 9 additions & 1 deletion src/app/Scenes/Fair/Fair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ interface FairQueryRendererProps {
}

const FairQueryRenderer: React.FC<FairQueryRendererProps> = ({ fairID }) => {
const data = useLazyLoadQuery<FairQuery>(query, { fairID })
const data = useLazyLoadQuery<FairQuery>(
query,
{ fairID },
{
networkCacheConfig: {
force: false,
},
}
)

if (!data?.fair) {
return null
Expand Down
7 changes: 6 additions & 1 deletion src/app/Scenes/HomeView/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export const HomeView: React.FC = () => {

const queryData = useLazyLoadQuery<HomeViewQuery>(
homeViewScreenQuery,
homeViewScreenQueryVariables()
homeViewScreenQueryVariables(),
{
networkCacheConfig: {
force: false,
},
}
)

const { data, loadNext, hasNext } = usePaginationFragment<
Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionArticles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,17 @@ const HomeViewSectionArticlesPlaceholder: React.FC<FlexProps> = (flexProps) => {

export const HomeViewSectionArticlesQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionArticlesQuery>(homeViewSectionArticlesQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionArticlesQuery>(
homeViewSectionArticlesQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ export const HomeViewSectionArticlesCardsQueryRenderer: React.FC<SectionSharedPr
homeViewSectionArticlesCardsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionFairs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,17 @@ const homeViewSectionFairsQuery = graphql`

export const HomeViewSectionFairsQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionFairsQuery>(homeViewSectionFairsQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionFairsQuery>(
homeViewSectionFairsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ export const HomeViewSectionFeaturedCollectionQueryRenderer: React.FC<SectionSha
homeViewSectionFeaturedCollectionQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionGalleries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,17 @@ const homeViewSectionGalleriesQuery = graphql`

export const HomeViewSectionGalleriesQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionGalleriesQuery>(homeViewSectionGalleriesQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionGalleriesQuery>(
homeViewSectionGalleriesQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionHeroUnits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,17 @@ const homeViewSectionHeroUnitsQuery = graphql`

export const HomeViewSectionHeroUnitsQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionHeroUnitsQuery>(homeViewSectionHeroUnitsQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionHeroUnitsQuery>(
homeViewSectionHeroUnitsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ export const HomeViewSectionMarketingCollectionsQueryRenderer: React.FC<SectionS
homeViewSectionMarketingCollectionsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionSales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,17 @@ const homeViewSectionSalesQuery = graphql`

export const HomeViewSectionSalesQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionSalesQuery>(homeViewSectionSalesQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionSalesQuery>(
homeViewSectionSalesQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
14 changes: 11 additions & 3 deletions src/app/Scenes/HomeView/Sections/HomeViewSectionShows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ const homeViewSectionShowsQuery = graphql`

export const HomeViewSectionShowsQueryRenderer: React.FC<SectionSharedProps> = withSuspense(
({ sectionID, index, ...flexProps }) => {
const data = useLazyLoadQuery<HomeViewSectionShowsQuery>(homeViewSectionShowsQuery, {
id: sectionID,
})
const data = useLazyLoadQuery<HomeViewSectionShowsQuery>(
homeViewSectionShowsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

if (!data.homeView.section) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export const HomeViewSectionViewingRoomsQueryRenderer: React.FC<SectionSharedPro
homeViewSectionViewingRoomsQuery,
{
id: sectionID,
},
{
networkCacheConfig: {
force: false,
},
}
)

Expand Down
3 changes: 3 additions & 0 deletions src/app/Scenes/Partner/Partner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export const PartnerQueryRenderer: React.FC<{
partnerID,
displayArtistsSection: data?.partner?.displayArtistsSection ?? true,
}}
cacheConfig={{
force: false,
}}
render={renderWithPlaceholder({
Container: PartnerContainer,
initialProps: others,
Expand Down
3 changes: 3 additions & 0 deletions src/app/Scenes/Show/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ export const ShowQueryRenderer: React.FC<ShowQueryRendererProps> = ({ showID })
}
`}
variables={{ showID }}
cacheConfig={{
force: false,
}}
render={renderWithPlaceholder({
Container: ShowFragmentContainer,
renderPlaceholder: () => <ShowPlaceholder />,
Expand Down
2 changes: 1 addition & 1 deletion src/app/Scenes/ViewingRoom/ViewingRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const ViewingRoomQueryRenderer: React.FC<{ viewing_room_id: string }> = (
}
}
`}
cacheConfig={{ force: true }}
cacheConfig={{ force: false }}
variables={{
viewingRoomID,
}}
Expand Down
5 changes: 5 additions & 0 deletions src/app/system/relay/middlewares/cacheHeaderMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ export const RELAY_CACHE_PATH_HEADER_KEY = "x-relay-cache-path"
export const shouldSkipCDNCache = (req: GraphQLRequest, url: string | undefined) => {
// The order of these checks is important.
// We only want to use CDN cache if:
// - force is false in the cacheConfig
// - @cacheable is present on the query
// - the query does not have any of the following arguments:
// - a known personalized argument is present in the query (for example `include_artworks_by_followed_artists`)
// - nocache param is present in the url

if (req.cacheConfig?.force === true) {
return true
}

if (isRequestCacheable(req)) {
if (url && hasNoCacheParamPresent(url)) {
// Don't use CDN cache if the url has the nocache param
Expand Down

0 comments on commit 388a95d

Please sign in to comment.