Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HomeRecommendationCandidateService(
if (serviceId != YOUTUBE_SERVICE_ID) {
return HomeRecommendationCandidatePool(subscriptions = emptyList(), discovery = emptyList())
}
return shortsCandidateService.fetch(userId, serviceId, profile, signalContext, this)
return shortsCandidateService.fetch(userId, profile, signalContext, this)
}
val subscriptions = fetchSubscriptionCandidates(userId, mode)
.map { HomeRecommendationTaggedVideo(it, HomeRecommendationSourceTag.SUBSCRIPTION) }
Expand Down Expand Up @@ -81,4 +81,12 @@ class HomeRecommendationCandidateService(
source: HomeRecommendationSourceTag,
): List<HomeRecommendationTaggedVideo> =
searchCandidateFetcher.fetchSearchCandidates(serviceId, queries, maxQueries, perQueryLimit, source)

suspend fun fetchRelatedCandidates(
seedUrls: List<String>,
source: HomeRecommendationSourceTag,
seedLimit: Int,
relatedPerSeedLimit: Int,
): List<HomeRecommendationTaggedVideo> =
relatedCandidateService.fetch(seedUrls, source, seedLimit, relatedPerSeedLimit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.typetype.server.services
class HomeRecommendationShortsCandidateService {
suspend fun fetch(
userId: String,
serviceId: Int,
profile: HomeRecommendationProfile,
signalContext: HomeRecommendationSignalContext,
candidateService: HomeRecommendationCandidateService,
Expand All @@ -15,24 +14,28 @@ class HomeRecommendationShortsCandidateService {
.take(HomeRecommendationShortsSources.SUBSCRIPTION_LIMIT)
.map { HomeRecommendationTaggedVideo(it, HomeRecommendationSourceTag.SUBSCRIPTION) }
.toList()
val discoveryCandidates = candidateService.fetchTrendingCandidates(serviceId)
val relatedFromSubscriptions = candidateService.fetchRelatedCandidates(
seedUrls = subscriptions.map { it.video.url },
source = HomeRecommendationSourceTag.DISCOVERY_THEME,
seedLimit = HomeRecommendationCandidateLimits.SUBSCRIPTION_SEED_LIMIT,
relatedPerSeedLimit = HomeRecommendationCandidateLimits.RELATED_PER_SEED_LIMIT,
)
.asSequence()
.map { it.copy(video = it.video.copy(isShortFormContent = it.video.isShortFormContent || it.video.duration in 1L..85L)) }
.filter { it.video.isShortFormContent }
.toList()
val exploration = candidateService.fetchSearchCandidates(
serviceId = serviceId,
queries = HomeRecommendationShortsQueryFactory.fromProfile(profile),
maxQueries = HomeRecommendationShortsSources.SEARCH_QUERY_LIMIT,
perQueryLimit = HomeRecommendationShortsSources.SEARCH_PER_QUERY_LIMIT,
val relatedFromFavorites = candidateService.fetchRelatedCandidates(
seedUrls = signalContext.favoriteUrls,
source = HomeRecommendationSourceTag.DISCOVERY_EXPLORATION,
seedLimit = HomeRecommendationCandidateLimits.FAVORITE_SEED_LIMIT,
relatedPerSeedLimit = HomeRecommendationCandidateLimits.RELATED_PER_SEED_LIMIT,
).asSequence()
.map { it.copy(video = it.video.copy(isShortFormContent = it.video.isShortFormContent || it.video.duration in 1L..85L)) }
.filter { it.video.isShortFormContent }
.toList()
val discovery = HomeRecommendationDiscoveryAssembler().build(
profile = profile,
candidates = discoveryCandidates + exploration,
candidates = relatedFromSubscriptions + relatedFromFavorites,
explorationCap = HomeRecommendationShortsSources.DISCOVERY_CAP,
)
val dedupedSubscriptions = HomeRecommendationShortsDeduplicator.apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class HomeRecommendationShortsRoutesTest {
}
assertEquals(HttpStatusCode.OK, response.status)
val body = response.bodyAsText()
assertTrue(body.contains("/v/s1") || body.contains("/v/s2"))
assertTrue(!body.contains("/v/l1"))
}

Expand Down