From 05db5c94fac23cda8a36e928c03d1008d73f6882 Mon Sep 17 00:00:00 2001 From: Fernando Lucchesi Date: Wed, 29 Nov 2023 10:13:35 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20Prevent=20race=20condition?= =?UTF-8?q?=20between=20delete=20and=20update=20requests=20#1998=20(#2002)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Prevent race condition between delete and update requests #1998 * 🐛 Add missing promise wrapper #1998 --- search/IndexSanityContent/events/index.ts | 30 +++++++++--------- search/IndexSanityContent/localNews/index.ts | 31 ++++++++++--------- search/IndexSanityContent/magazine/index.ts | 30 +++++++++--------- search/IndexSanityContent/news/index.ts | 31 ++++++++++--------- search/IndexSanityContent/topic/index.ts | 32 +++++++++++--------- web/pages/magazine/index.global.tsx | 8 +---- 6 files changed, 85 insertions(+), 77 deletions(-) diff --git a/search/IndexSanityContent/events/index.ts b/search/IndexSanityContent/events/index.ts index 4c409d30f..49c6919c4 100644 --- a/search/IndexSanityContent/events/index.ts +++ b/search/IndexSanityContent/events/index.ts @@ -15,19 +15,21 @@ export const indexEvents = (language: Language) => (docId: string) => { const updateAlgolia = flow(indexName, E.map(flow(update, ap(indexSettings)))) const removeIndexFromAlgolia = flow(indexName, E.map(remove)) - type RemoveAndMapType = (pages: Event[]) => EventIndex[] - const removeAndMap: RemoveAndMapType = (pages) => { - pages - .filter((page) => page.docToClear) - .map((page) => - pipe( - removeIndexFromAlgolia(), - E.ap(E.of(page.slug)), - TE.fromEither, - TE.flatten, - T.map(E.fold(console.error, console.log)), - )(), - ) + type RemoveAndMapType = (pages: Event[]) => Promise + const removeAndMap: RemoveAndMapType = async (pages) => { + await Promise.all( + pages + .filter((page) => page.docToClear) + .map((page) => + pipe( + removeIndexFromAlgolia(), + E.ap(E.of(page.slug)), + TE.fromEither, + TE.flatten, + T.map(E.fold(console.error, console.log)), + )(), + ), + ) return pipe(pages.map(mapData)) } @@ -35,7 +37,7 @@ export const indexEvents = (language: Language) => (docId: string) => { getSanityClient(), TE.fromEither, TE.chainW(fetchData(language, docId)), - TE.map(removeAndMap), + TE.chainW((pages) => TE.fromTask(() => removeAndMap(pages))), TE.chainW((data) => pipe(updateAlgolia(), E.ap(E.of(data)), TE.fromEither)), TE.flatten, T.map(E.fold(console.error, console.log)), diff --git a/search/IndexSanityContent/localNews/index.ts b/search/IndexSanityContent/localNews/index.ts index 442f57245..5591749fa 100644 --- a/search/IndexSanityContent/localNews/index.ts +++ b/search/IndexSanityContent/localNews/index.ts @@ -16,19 +16,22 @@ export const indexLocalNews = (language: Language) => (docId: string) => { const updateAlgolia = flow(indexName, E.map(flow(update, ap(indexSettings)))) const removeIndexFromAlgolia = flow(indexName, E.map(remove)) - type RemoveAndMapType = (pages: LocalNewsArticle[]) => NewsIndex[] - const removeAndMap: RemoveAndMapType = (pages) => { - pages - .filter((page) => page.docToClear) - .map((page) => - pipe( - removeIndexFromAlgolia(), - E.ap(E.of(page.slug)), - TE.fromEither, - TE.flatten, - T.map(E.fold(console.error, console.log)), - )(), - ) + type RemoveAndMapType = (pages: LocalNewsArticle[]) => Promise + const removeAndMap: RemoveAndMapType = async (pages) => { + await Promise.all( + pages + .filter((page) => page.docToClear) + .map((page) => + pipe( + removeIndexFromAlgolia(), + E.ap(E.of(page.slug)), + TE.fromEither, + TE.flatten, + T.map(E.fold(console.error, console.log)), + )(), + ), + ) + return pipe(pages.map(mapData), flatten) } @@ -36,7 +39,7 @@ export const indexLocalNews = (language: Language) => (docId: string) => { getSanityClient(), TE.fromEither, TE.chainW(fetchData(language, docId)), - TE.map(removeAndMap), + TE.chainW((pages) => TE.fromTask(() => removeAndMap(pages))), TE.chainW((data) => pipe(updateAlgolia(), E.ap(E.of(data)), TE.fromEither)), TE.flatten, T.map(E.fold(console.error, console.log)), diff --git a/search/IndexSanityContent/magazine/index.ts b/search/IndexSanityContent/magazine/index.ts index 66a79ed93..5369d5ea1 100644 --- a/search/IndexSanityContent/magazine/index.ts +++ b/search/IndexSanityContent/magazine/index.ts @@ -24,26 +24,28 @@ export const indexMagazine = (language: Language) => (docId: string) => { const updateAlgolia = flow(indexName, E.map(flow(update, ap(indexSettings)))) const removeIndexFromAlgolia = flow(indexName, E.map(remove)) - type RemoveAndMapType = (pages: MagazineArticle[]) => MagazineIndex[] - const removeAndMap: RemoveAndMapType = (pages) => { - pages - .filter((page) => page.docToClear) - .map((page) => - pipe( - removeIndexFromAlgolia(), - E.ap(E.of(page.slug)), - TE.fromEither, - TE.flatten, - T.map(E.fold(console.error, console.log)), - )(), - ) + type RemoveAndMapType = (pages: MagazineArticle[]) => Promise + const removeAndMap: RemoveAndMapType = async (pages) => { + await Promise.all( + pages + .filter((page) => page.docToClear) + .map((page) => + pipe( + removeIndexFromAlgolia(), + E.ap(E.of(page.slug)), + TE.fromEither, + TE.flatten, + T.map(E.fold(console.error, console.log)), + )(), + ), + ) return pipe(pages.map(mapData), flatten) } return pipe( getSanityClient(), TE.fromEither, TE.chainW(fetchData(language, docId)), - TE.map(removeAndMap), + TE.chainW((pages) => TE.fromTask(() => removeAndMap(pages))), TE.chainW((data) => pipe(updateAlgolia(), E.ap(E.of(data)), TE.fromEither)), TE.flatten, T.map(E.fold(console.error, console.log)), diff --git a/search/IndexSanityContent/news/index.ts b/search/IndexSanityContent/news/index.ts index 6061f923c..d1487525f 100644 --- a/search/IndexSanityContent/news/index.ts +++ b/search/IndexSanityContent/news/index.ts @@ -16,19 +16,22 @@ export const indexNews = (language: Language) => (docId: string) => { const updateAlgolia = flow(indexName, E.map(flow(update, ap(indexSettings)))) const removeIndexFromAlgolia = flow(indexName, E.map(remove)) - type RemoveAndMapType = (pages: NewsArticle[]) => NewsIndex[] - const removeAndMap: RemoveAndMapType = (pages) => { - pages - .filter((page) => page.docToClear) - .map((page) => - pipe( - removeIndexFromAlgolia(), - E.ap(E.of(page.slug)), - TE.fromEither, - TE.flatten, - T.map(E.fold(console.error, console.log)), - )(), - ) + type RemoveAndMapType = (pages: NewsArticle[]) => Promise + + const removeAndMap: RemoveAndMapType = async (pages) => { + await Promise.all( + pages + .filter((page) => page.docToClear) + .map((page) => + pipe( + removeIndexFromAlgolia(), + E.ap(E.of(page.slug)), + TE.fromEither, + TE.flatten, + T.map(E.fold(console.error, console.log)), + )(), + ), + ) return pipe(pages.map(mapData), flatten) } @@ -36,7 +39,7 @@ export const indexNews = (language: Language) => (docId: string) => { getSanityClient(), TE.fromEither, TE.chainW(fetchData(language, docId)), - TE.map(removeAndMap), + TE.chainW((pages) => TE.fromTask(() => removeAndMap(pages))), TE.chainW((data) => pipe(updateAlgolia(), E.ap(E.of(data)), TE.fromEither)), TE.flatten, T.map(E.fold(console.error, console.log)), diff --git a/search/IndexSanityContent/topic/index.ts b/search/IndexSanityContent/topic/index.ts index c575e5a92..40b851018 100644 --- a/search/IndexSanityContent/topic/index.ts +++ b/search/IndexSanityContent/topic/index.ts @@ -16,19 +16,23 @@ export const indexTopic = (language: Language) => (docId: string) => { const updateAlgolia = flow(indexName, E.map(flow(update, ap(indexSettings)))) const removeIndexFromAlgolia = flow(indexName, E.map(remove)) - type RemoveAndMapType = (pages: TopicPage[]) => TopicIndex[] - const removeAndMap: RemoveAndMapType = (pages) => { - pages - .filter((page) => page.docToClear) - .map((page) => - pipe( - removeIndexFromAlgolia(), - E.ap(E.of(page.slug)), - TE.fromEither, - TE.flatten, - T.map(E.fold(console.error, console.log)), - )(), - ) + type RemoveAndMapType = (pages: TopicPage[]) => Promise + + const removeAndMap: RemoveAndMapType = async (pages) => { + await Promise.all( + pages + .filter((page) => page.docToClear) + .map((page) => + pipe( + removeIndexFromAlgolia(), + E.ap(E.of(page.slug)), + TE.fromEither, + TE.flatten, + T.map(E.fold(console.error, console.log)), + )(), + ), + ) + return pipe(pages.map(mapData), flatten) } @@ -36,7 +40,7 @@ export const indexTopic = (language: Language) => (docId: string) => { getSanityClient(), TE.fromEither, TE.chainW(fetchData(language, docId)), - TE.map(removeAndMap), + TE.chainW((pages) => TE.fromTask(() => removeAndMap(pages))), TE.chainW((data) => pipe(updateAlgolia(), E.ap(E.of(data)), TE.fromEither)), TE.flatten, T.map(E.fold(console.error, console.log)), diff --git a/web/pages/magazine/index.global.tsx b/web/pages/magazine/index.global.tsx index eecc2aff3..23a07cbdb 100644 --- a/web/pages/magazine/index.global.tsx +++ b/web/pages/magazine/index.global.tsx @@ -1,6 +1,5 @@ import { GetServerSideProps } from 'next' -import { InstantSearchSSRProvider } from 'react-instantsearch' -import { getServerState } from 'react-instantsearch' +import { InstantSearchSSRProvider, getServerState } from 'react-instantsearch' import type { AppProps } from 'next/app' import { IntlProvider } from 'react-intl' import Footer from '../../pageComponents/shared/Footer' @@ -67,11 +66,6 @@ MagazineIndex.getLayout = (page: AppProps) => { } export const getServerSideProps: GetServerSideProps = async ({ req, preview = false, locale = 'en' }) => { - // For the time being, let's just give 404 for satellites - // We will also return 404 if the locale is not English. - // This is a hack and and we should improve this at some point - // See https://github.com/vercel/next.js/discussions/18485 - if (locale !== 'en') { return { notFound: true, From f5b9c9759f8d05cf0b688de82f64e754f0faa41e Mon Sep 17 00:00:00 2001 From: Padmaja Date: Wed, 29 Nov 2023 16:51:42 +0530 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=A8=20Script=20for=20replacing=20s?= =?UTF-8?q?ecret=20site=20reference=20on=20assets=20(#1968)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/issue-1626/fix-asset-urls.mjs | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 sanityv3/scripts/issue-1626/fix-asset-urls.mjs diff --git a/sanityv3/scripts/issue-1626/fix-asset-urls.mjs b/sanityv3/scripts/issue-1626/fix-asset-urls.mjs new file mode 100644 index 000000000..943cf89e1 --- /dev/null +++ b/sanityv3/scripts/issue-1626/fix-asset-urls.mjs @@ -0,0 +1,110 @@ +//import { type SourceOptions } from 'sanity' +//import { getCliClient } from 'sanity/cli' +//import { sanityClient } from '../../sanity.client' +import { createClient } from '@sanity/client' + +const dataset = 'global-development' +const client = createClient({ + apiVersion: '2023-08-29', + projectId: process.env.SANITY_STUDIO_API_PROJECT_ID || 'h61q9gi9', + token: process.env.SANITY_STUDIO_MUTATION_TOKEN, + dataset: dataset, +}) + +const config = client.config() +/* +const client = getCliClient() +const config = client.config() + +type ProjectDetails = Pick + +interface AssetDocument { + _id: string + url: string + path: string +}*/ + +/** + * Ensures the required configuration properties are set. + */ +function isConfigValid(config) { + return typeof config.projectId !== 'undefined' && typeof config.dataset !== 'undefined' +} + +/** + * Creates a function that transforms a path string (segments seperated by a `/` + * character), replacing the `${projectId}/${dataset}` segments at the given + * position with the given project details. + */ +function createFixFunction(position) { + return (input, { projectId, dataset }) => { + const input2 = input.split('/').slice() // create a copy of the array + input2.splice(position, 2, projectId, dataset) + return input2.join('/') + //return input.split('/').toSpliced(position, 2, projectId, dataset).join('/') + } +} + +/** + * Replaces the `${projectId}/${dataset}` segments in the given path. + */ +const fixPath = createFixFunction(1) + +/** + * Replaces the `${projectId}/${dataset}` segments in the given URL. + */ +const fixUrl = createFixFunction(4) + +/** + * Queries Sanity dataset for assets that have a `url` or `path` field that + * doesn't match the provided project details. + */ +function fetchBrokenAssets({ projectId, dataset }) { + return client.fetch( + ` + *[ + _type in ["sanity.imageAsset", "sanity.fileAsset"] + && ( + count(string::split(url, $expectedPath)) != 2 + || count(string::split(path, $expectedPath)) != 2 + ) + ] { + _id, + url, + path + }`, + { + expectedPath: `/${projectId}/${dataset}/`, + }, + ) +} + +/** + * Queries Sanity dataset for assets that have a `url` or `path` field that + * doesn't match the provided project details, and patches them with fields + * that do match. + */ +async function fixAssets(projectDetails) { + const assets = await fetchBrokenAssets(projectDetails) + + const transaction = assets.reduce((transaction, asset) => { + return transaction.patch(asset._id, (patch) => + patch.set({ + url: fixUrl(asset.url, projectDetails), + path: fixPath(asset.path, projectDetails), + }), + ) + }, client.transaction()) + + console.log(JSON.stringify(transaction)) + const result = await transaction.commit() + + console.log(`Fixed ${result.documentIds.length} documents.`) + console.log(result.documentIds) +} + +if (!isConfigValid(config)) { + throw new Error('Please specify your project details.') +} + +fixAssets(config) From e96b0e1a91ac24b9b2e436eceb6ac7aa405f1586 Mon Sep 17 00:00:00 2001 From: Padmaja <52911293+padms@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:13:17 +0530 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20Add=20dudgeon=20and=20sheringha?= =?UTF-8?q?m=20datasets=20#1994?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FeatureFlags.js | 2 ++ satellites.json | 15 ++++++++++++++- satellitesConfig.js | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/FeatureFlags.js b/FeatureFlags.js index 0a25e81d8..25555ab21 100644 --- a/FeatureFlags.js +++ b/FeatureFlags.js @@ -15,6 +15,8 @@ const SATELLITES = [ 'poland', 'southkorea', 'storage', + 'sheringham', + 'dudgeon', ] const NEWS = [...GLOBAL_DEV, ...GLOBAL_PROD, 'japan', 'poland', 'brazil', 'germany', 'southkorea', 'celticsea'] const ARCHIVED_NEWS = [...GLOBAL_PROD, ...GLOBAL_DEV] diff --git a/satellites.json b/satellites.json index d311010e3..740c3caa0 100644 --- a/satellites.json +++ b/satellites.json @@ -1 +1,14 @@ -["global", "brazil", "germany", "argentina", "poland", "japan", "storage", "equinorfunds", "southkorea", "celticsea"] +[ + "global", + "brazil", + "germany", + "argentina", + "poland", + "japan", + "storage", + "equinorfunds", + "southkorea", + "celticsea", + "dudgeon", + "sheringham" +] diff --git a/satellitesConfig.js b/satellitesConfig.js index 2f16358dd..f9081f2fc 100644 --- a/satellitesConfig.js +++ b/satellitesConfig.js @@ -67,6 +67,8 @@ const datasets = { equinorfunds: ['norwegian'], southkorea: ['english', 'korean'], celticsea: ['english', 'welsh'], + sheringham: ['english'], + dudgeon: ['english'], // Test datasets 'global-development': ['english', 'norwegian', 'japanese'], 'global-test': ['english', 'norwegian', 'japanese'], From 75297f9ab71384218f6a6c2b2ff0492d6352f46b Mon Sep 17 00:00:00 2001 From: Padmaja <52911293+padms@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:17:37 +0530 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20Add=20news=20feature=20for=20ne?= =?UTF-8?q?w=20satellite=20sites=20#1995?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FeatureFlags.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/FeatureFlags.js b/FeatureFlags.js index 25555ab21..97bd8a7fd 100644 --- a/FeatureFlags.js +++ b/FeatureFlags.js @@ -18,7 +18,18 @@ const SATELLITES = [ 'sheringham', 'dudgeon', ] -const NEWS = [...GLOBAL_DEV, ...GLOBAL_PROD, 'japan', 'poland', 'brazil', 'germany', 'southkorea', 'celticsea'] +const NEWS = [ + ...GLOBAL_DEV, + ...GLOBAL_PROD, + 'japan', + 'poland', + 'brazil', + 'germany', + 'southkorea', + 'celticsea', + 'dudgeon', + 'sheringham', +] const ARCHIVED_NEWS = [...GLOBAL_PROD, ...GLOBAL_DEV] const NEWS_SUBSCRIPTION = [...GLOBAL_PROD, ...GLOBAL_DEV] const MAGAZINE_SUBSCRIPTION = [...GLOBAL_DEV, ...GLOBAL_PROD] From 0908d16262bcfeaf4e87e16ce4fabe16db503d82 Mon Sep 17 00:00:00 2001 From: Padmaja <52911293+padms@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:44:19 +0530 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8=20Meta=20for=20new=20satellite=20?= =?UTF-8?q?sites=20#1995?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- satellitesConfig.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/satellitesConfig.js b/satellitesConfig.js index f9081f2fc..9fc782691 100644 --- a/satellitesConfig.js +++ b/satellitesConfig.js @@ -132,6 +132,14 @@ const websiteDomains = { url: 'https://www.equinorcelticsea.co.uk', meta: 'equinorcelticsea.co.uk', }, + dudgeon: { + url: 'https://web-dudgeon-equinor-web-sites-preprod.c2.radix.equinor.com/', + meta: 'Dudgeon', + }, + sheringham: { + url: 'https://web-sheringham-equinor-web-sites-preprod.c2.radix.equinor.com/', + meta: 'Sheringham Shoal', + }, 'global-development': { url: 'localhost:3000', meta: 'Equinor',