From 32ba1a8acabab0562534da97bd7f6e60af9cb859 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Mon, 30 Oct 2023 14:41:47 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20wp-posts-with-successors?= =?UTF-8?q?=20getting=20indexed=20in=20algolia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baker/algolia/indexToAlgolia.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/baker/algolia/indexToAlgolia.tsx b/baker/algolia/indexToAlgolia.tsx index 35dd78c5622..472117ba0a4 100644 --- a/baker/algolia/indexToAlgolia.tsx +++ b/baker/algolia/indexToAlgolia.tsx @@ -188,10 +188,18 @@ const getPagesRecords = async () => { const pageviews = await Pageview.getViewsByUrlObj() const gdocs = await Gdoc.getPublishedGdocs() const publishedGdocsBySlug = keyBy(gdocs, "slug") - const postsApi = await wpdb.getPosts( - undefined, - (post) => !publishedGdocsBySlug[`/${post.slug}`] - ) + const slugsWithPublishedGdocsSuccessors = + await db.getSlugsWithPublishedGdocsSuccessors() + const postsApi = await wpdb.getPosts(undefined, (post) => { + // Two things can happen here: + // 1. There's a published Gdoc with the same slug + // 2. This post has a Gdoc successor (which might have a different slug) + // In either case, we don't want to index this WP post + return !( + publishedGdocsBySlug[post.slug] || + slugsWithPublishedGdocsSuccessors.has(post.slug) + ) + }) const countryRecords = generateCountryRecords(countries, pageviews) const wordpressRecords = await generateWordpressRecords(postsApi, pageviews)