From 3a0730d1b03c50fac1c3a5064f249617e491833c Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Wed, 18 Dec 2024 09:49:23 +0000 Subject: [PATCH] Force CMS updates to appear I've been unable to work out what's happening, but pages from the CMS haven't been updated. The revalidation request is made, but it uses the cached copy again rather than revalidating. I'm unsure if this is related to the recent changes to how content is read from the CMS, but it seems likely. If not, there might be a wider problem (as a lot of content uses this technique). To force through the changes, this commit removes the stale caching at the cost of a small performance/reliability regression. Refs 201a9d41b2937183f2e873cc1acf84e790e25076, https://prereview.slack.com/archives/CR6B5804W/p1734390769283349?thread_ts=1734382300.226219&cid=CR6B5804W --- src/ghost.ts | 7 ++----- test/clubs.test.ts | 5 ++--- test/code-of-conduct.test.ts | 5 ++--- test/edia-statement.test.ts | 5 ++--- test/funding.test.ts | 5 ++--- test/ghost.test.ts | 40 ------------------------------------ test/how-to-use.test.ts | 5 ++--- test/live-reviews.test.ts | 5 ++--- test/people.test.ts | 5 ++--- test/privacy-policy.test.ts | 5 ++--- test/resources.test.ts | 5 ++--- test/trainings.test.ts | 5 ++--- 12 files changed, 22 insertions(+), 75 deletions(-) diff --git a/src/ghost.ts b/src/ghost.ts index 6be63ccb6..08dfd1d71 100644 --- a/src/ghost.ts +++ b/src/ghost.ts @@ -3,11 +3,10 @@ import { Context, Data, Effect, flow, identity, Match, Schema } from 'effect' import type * as F from 'fetch-fp-ts' import * as E from 'fp-ts/lib/Either.js' import * as R from 'fp-ts/lib/Reader.js' -import * as RTE from 'fp-ts/lib/ReaderTaskEither.js' +import type * as RTE from 'fp-ts/lib/ReaderTaskEither.js' import { pipe } from 'fp-ts/lib/function.js' import { StatusCodes } from 'http-status-codes' import { URL } from 'url' -import { type SleepEnv, revalidateIfStale, useStaleCache } from './fetch.js' import { type Html, rawHtml, sanitizeHtml } from './html.js' export interface GhostApiEnv { @@ -32,7 +31,7 @@ const GhostPageSchema = Schema.Struct({ export const getPage = ( id: string, -): RTE.ReaderTaskEither => +): RTE.ReaderTaskEither => pipe( R.asks( (env: GhostApiEnv & F.FetchEnv) => () => @@ -49,8 +48,6 @@ export const getPage = ( Effect.runPromise, ), ), - RTE.local(revalidateIfStale()), - RTE.local(useStaleCache()), ) export class GhostApi extends Context.Tag('GhostApi')() {} diff --git a/test/clubs.test.ts b/test/clubs.test.ts index 3fbceae32..932109875 100644 --- a/test/clubs.test.ts +++ b/test/clubs.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/clubs.js' import { clubsMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('clubs', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('clubs', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.clubs({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.clubs({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('clubs', () => { response, ) - const actual = await _.clubs({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.clubs({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/code-of-conduct.test.ts b/test/code-of-conduct.test.ts index a6ace1211..3137967f7 100644 --- a/test/code-of-conduct.test.ts +++ b/test/code-of-conduct.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/code-of-conduct.js' import { codeOfConductMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('codeOfConduct', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('codeOfConduct', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.codeOfConduct({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.codeOfConduct({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('codeOfConduct', () => { response, ) - const actual = await _.codeOfConduct({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.codeOfConduct({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/edia-statement.test.ts b/test/edia-statement.test.ts index 3bd4a8b5e..b679091a4 100644 --- a/test/edia-statement.test.ts +++ b/test/edia-statement.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/edia-statement.js' import { ediaStatementMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('ediaStatement', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('ediaStatement', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.ediaStatement({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.ediaStatement({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('ediaStatement', () => { response, ) - const actual = await _.ediaStatement({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.ediaStatement({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/funding.test.ts b/test/funding.test.ts index f3ceb2b56..13a4ee5f6 100644 --- a/test/funding.test.ts +++ b/test/funding.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/funding.js' import { fundingMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('funding', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('funding', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.funding({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.funding({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('funding', () => { response, ) - const actual = await _.funding({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.funding({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/ghost.test.ts b/test/ghost.test.ts index d39cf04af..e57501ea9 100644 --- a/test/ghost.test.ts +++ b/test/ghost.test.ts @@ -2,12 +2,10 @@ import { test } from '@fast-check/jest' import { describe, expect } from '@jest/globals' import fetchMock from 'fetch-mock' import * as E from 'fp-ts/lib/Either.js' -import * as T from 'fp-ts/lib/Task.js' import { Status } from 'hyper-ts' import * as _ from '../src/ghost.js' import { rawHtml } from '../src/html.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('getPage', () => { test.prop([ @@ -23,7 +21,6 @@ describe('getPage', () => { { body: { pages: [{ html: html.toString() }] } }, ), ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.right(html)) @@ -47,7 +44,6 @@ describe('getPage', () => { }, ), ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual( @@ -77,7 +73,6 @@ describe('getPage', () => { }, ), ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual( @@ -107,42 +102,11 @@ describe('getPage', () => { }, ), ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.right(rawHtml('Donate'))) }) - test.prop([ - fc.string({ unit: fc.alphanumeric(), minLength: 1 }), - fc.string({ unit: fc.alphanumeric(), minLength: 1 }), - fc.sanitisedHtml(), - ])("revalidates the page if it's stale", async (id, key, html) => { - const fetch = fetchMock - .sandbox() - .getOnce( - (requestUrl, { cache }) => - requestUrl === `https://content.prereview.org/ghost/api/content/pages/${id}?key=${key}` && - cache === 'force-cache', - { body: { pages: [{ html: html.toString() }] }, headers: { 'X-Local-Cache-Status': 'stale' } }, - ) - .getOnce( - (requestUrl, { cache }) => - requestUrl === `https://content.prereview.org/ghost/api/content/pages/${id}?key=${key}` && - cache === 'no-cache', - { throws: new Error('Network error') }, - ) - - const actual = await _.getPage(id)({ - fetch, - ghostApi: { key }, - sleep: () => T.of(undefined), - })() - - expect(actual).toStrictEqual(E.right(html)) - expect(fetch.done()).toBeTruthy() - }) - test.prop([ fc.string({ unit: fc.alphanumeric(), minLength: 1 }), fc.string({ unit: fc.alphanumeric(), minLength: 1 }), @@ -155,7 +119,6 @@ describe('getPage', () => { const actual = await _.getPage(id)({ fetch, ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.left('unavailable')) @@ -173,7 +136,6 @@ describe('getPage', () => { const actual = await _.getPage(id)({ fetch, ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.left('not-found')) @@ -191,7 +153,6 @@ describe('getPage', () => { const actual = await _.getPage(id)({ fetch, ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.left('unavailable')) @@ -206,7 +167,6 @@ describe('getPage', () => { const actual = await _.getPage(id)({ fetch: () => Promise.reject(error), ghostApi: { key }, - sleep: shouldNotBeCalled, })() expect(actual).toStrictEqual(E.left('unavailable')) diff --git a/test/how-to-use.test.ts b/test/how-to-use.test.ts index c0c141157..8af1df187 100644 --- a/test/how-to-use.test.ts +++ b/test/how-to-use.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/how-to-use.js' import { howToUseMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('howToUse', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('howToUse', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.howToUse({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.howToUse({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('howToUse', () => { response, ) - const actual = await _.howToUse({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.howToUse({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/live-reviews.test.ts b/test/live-reviews.test.ts index fb038ef19..9a8e2c083 100644 --- a/test/live-reviews.test.ts +++ b/test/live-reviews.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/live-reviews.js' import { liveReviewsMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('liveReviews', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('liveReviews', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.liveReviews({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.liveReviews({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('liveReviews', () => { response, ) - const actual = await _.liveReviews({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.liveReviews({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/people.test.ts b/test/people.test.ts index e2f5c0b93..b0dd3b61f 100644 --- a/test/people.test.ts +++ b/test/people.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/people.js' import { peopleMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('people', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('people', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.people({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.people({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('people', () => { response, ) - const actual = await _.people({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.people({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/privacy-policy.test.ts b/test/privacy-policy.test.ts index 844d7927f..63b10841f 100644 --- a/test/privacy-policy.test.ts +++ b/test/privacy-policy.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/privacy-policy.js' import { privacyPolicyMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('privacyPolicy', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('privacyPolicy', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.privacyPolicy({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.privacyPolicy({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('privacyPolicy', () => { response, ) - const actual = await _.privacyPolicy({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.privacyPolicy({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/resources.test.ts b/test/resources.test.ts index d774fd702..5d1a686a1 100644 --- a/test/resources.test.ts +++ b/test/resources.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import * as _ from '../src/resources.js' import { resourcesMatch } from '../src/routes.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('resources', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('resources', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.resources({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.resources({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('resources', () => { response, ) - const actual = await _.resources({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.resources({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', diff --git a/test/trainings.test.ts b/test/trainings.test.ts index 59cfe3ee9..90a7aa053 100644 --- a/test/trainings.test.ts +++ b/test/trainings.test.ts @@ -6,7 +6,6 @@ import { Status } from 'hyper-ts' import { trainingsMatch } from '../src/routes.js' import * as _ from '../src/trainings.js' import * as fc from './fc.js' -import { shouldNotBeCalled } from './should-not-be-called.js' describe('trainings', () => { test.prop([fc.string({ unit: fc.alphanumeric(), minLength: 1 })])('when the page can be loaded', async key => { @@ -18,7 +17,7 @@ describe('trainings', () => { { body: { pages: [{ html: '

Foo

' }] } }, ) - const actual = await _.trainings({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.trainings({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse', @@ -43,7 +42,7 @@ describe('trainings', () => { response, ) - const actual = await _.trainings({ fetch, ghostApi: { key }, sleep: shouldNotBeCalled })() + const actual = await _.trainings({ fetch, ghostApi: { key } })() expect(actual).toStrictEqual({ _tag: 'PageResponse',