From d58fb63c87414835b3ecd03193e2b37ceb7568d6 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 10 Nov 2022 18:49:52 +0800 Subject: [PATCH] Pre-fetch realistic voice only if user is opted in --- packages/api/src/services/speech.ts | 34 ++--------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/packages/api/src/services/speech.ts b/packages/api/src/services/speech.ts index 784d56840..c23dbb784 100644 --- a/packages/api/src/services/speech.ts +++ b/packages/api/src/services/speech.ts @@ -1,12 +1,8 @@ -import { searchPages } from '../elastic/pages' import { Page, PageType } from '../elastic/types' -import { SortBy, SortOrder } from '../utils/search' import { FeatureName, isOptedIn } from './features' /* - * We should not synthesize the page when: - ** 1. User has no recent listens the last 30 days - ** 2. User has a recent listen but the page was saved after the listen + * We should synthesize the page when user is opted in to the feature */ export const shouldSynthesize = async ( userId: string, @@ -17,31 +13,5 @@ export const shouldSynthesize = async ( return false } - if (await isOptedIn(FeatureName.UltraRealisticVoice, userId)) { - return true - } - - const [recentListenedPage, count] = (await searchPages( - { - dateFilters: [ - { - field: 'listenedAt', - startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), - }, - ], - sort: { - by: SortBy.LISTENED, - order: SortOrder.DESCENDING, - }, - size: 1, - }, - userId - )) || [[], 0] - if (count === 0) { - return false - } - return ( - !!recentListenedPage[0].listenedAt && - page.savedAt < recentListenedPage[0].listenedAt - ) + return isOptedIn(FeatureName.UltraRealisticVoice, userId) }