the-algorithm/timelineranker/server/src/main/scala/com/twitter/timelineranker/in_network_tweets/InNetworkTweetRepository.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

32 lines
1.1 KiB
Scala

package com.twitter.timelineranker.in_network_tweets
import com.twitter.timelineranker.model.CandidateTweetsResult
import com.twitter.timelineranker.model.RecapQuery
import com.twitter.timelineranker.model.RecapQuery.DependencyProvider
import com.twitter.timelineranker.parameters.in_network_tweets.InNetworkTweetParams
import com.twitter.util.Future
/**
* A repository of in-network tweet candidates.
* For now, it does not cache any results therefore forwards all calls to the underlying source.
*/
class InNetworkTweetRepository(
source: InNetworkTweetSource,
realtimeCGSource: InNetworkTweetSource) {
private[this] val enableRealtimeCGProvider =
DependencyProvider.from(InNetworkTweetParams.EnableEarlybirdRealtimeCgMigrationParam)
def get(query: RecapQuery): Future[CandidateTweetsResult] = {
if (enableRealtimeCGProvider(query)) {
realtimeCGSource.get(query)
} else {
source.get(query)
}
}
def get(queries: Seq[RecapQuery]): Future[Seq[CandidateTweetsResult]] = {
Future.collect(queries.map(query => get(query)))
}
}