mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-14 07:08:53 +02:00
ef4c5eb65e
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.
31 lines
1.2 KiB
Scala
31 lines
1.2 KiB
Scala
package com.twitter.timelineranker.common
|
|
|
|
import com.twitter.search.common.constants.thriftscala.ThriftLanguage
|
|
import com.twitter.servo.util.FutureArrow
|
|
import com.twitter.timelineranker.model.RecapQuery
|
|
import com.twitter.timelines.clients.manhattan.LanguageUtils
|
|
import com.twitter.timelines.clients.manhattan.UserMetadataClient
|
|
import com.twitter.timelines.util.FailOpenHandler
|
|
import com.twitter.util.Future
|
|
import com.twitter.service.metastore.gen.thriftscala.UserLanguages
|
|
|
|
object UserLanguagesTransform {
|
|
val EmptyUserLanguagesFuture: Future[UserLanguages] =
|
|
Future.value(UserMetadataClient.EmptyUserLanguages)
|
|
}
|
|
|
|
/**
|
|
* FutureArrow which fetches user languages
|
|
* It should be run in parallel with the main pipeline which fetches and hydrates CandidateTweets
|
|
*/
|
|
class UserLanguagesTransform(handler: FailOpenHandler, userMetadataClient: UserMetadataClient)
|
|
extends FutureArrow[RecapQuery, Seq[ThriftLanguage]] {
|
|
override def apply(request: RecapQuery): Future[Seq[ThriftLanguage]] = {
|
|
import UserLanguagesTransform._
|
|
|
|
handler {
|
|
userMetadataClient.getUserLanguages(request.userId)
|
|
} { _: Throwable => EmptyUserLanguagesFuture }
|
|
}.map(LanguageUtils.computeLanguages(_))
|
|
}
|