From c45b760f714d02f41fe2002a63c665205c208bc4 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 17 Aug 2023 18:42:11 +0800 Subject: [PATCH] fix test --- packages/api/src/elastic/pages.ts | 3 ++- packages/api/src/services/save_page.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/api/src/elastic/pages.ts b/packages/api/src/elastic/pages.ts index d1fba284a..de10b4432 100644 --- a/packages/api/src/elastic/pages.ts +++ b/packages/api/src/elastic/pages.ts @@ -430,8 +430,9 @@ export const createPage = async ( page.id = body._id as string + const shouldPublish = ctx.shouldPublish ?? true // only publish a pubsub event if we should - if (ctx.shouldPublish) { + if (shouldPublish) { await ctx.pubsub?.entityCreated(EntityType.PAGE, page, ctx.uid) } diff --git a/packages/api/src/services/save_page.ts b/packages/api/src/services/save_page.ts index fcac553fc..2acaa6755 100644 --- a/packages/api/src/services/save_page.ts +++ b/packages/api/src/services/save_page.ts @@ -118,6 +118,8 @@ export const savePage = async ( ? await createLabels(ctx, input.labels) : undefined + const isImported = input.source === 'csv-importer' + // always parse in backend if the url is in the force puppeteer list if (shouldParseInBackend(input)) { try { @@ -175,10 +177,9 @@ export const savePage = async ( } } else { // do not publish a pubsub event if the page is imported - const shouldPublish = input.source !== 'csv-importer' const newPageId = await createPage(articleToSave, { ...ctx, - shouldPublish, + shouldPublish: !isImported, }) if (!newPageId) { return { @@ -190,10 +191,10 @@ export const savePage = async ( } } - // create a task to update thumbnail and pre-cache all images - if (input.source !== 'csv-importer') { - // we don't want to create thumbnail for imported pages + // we don't want to create thumbnail for imported pages + if (!isImported) { try { + // create a task to update thumbnail and pre-cache all images const taskId = await enqueueThumbnailTask(saver.userId, slug) logger.info('Created thumbnail task', { taskId }) } catch (e) {