Pre-fetch realistic voice only if user is opted in

This commit is contained in:
Hongbo Wu 2022-11-10 18:49:52 +08:00
parent b0938ee96c
commit d58fb63c87

View file

@ -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)
}