the-algorithm/timelineranker/server/src/main/scala/com/twitter/timelineranker/common/UserProfileInfoTransform.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

30 lines
1.2 KiB
Scala

package com.twitter.timelineranker.common
import com.twitter.servo.util.FutureArrow
import com.twitter.timelineranker.model.RecapQuery
import com.twitter.timelines.clients.gizmoduck.GizmoduckClient
import com.twitter.timelines.clients.gizmoduck.UserProfileInfo
import com.twitter.timelines.util.FailOpenHandler
import com.twitter.util.Future
object UserProfileInfoTransform {
val EmptyUserProfileInfo: UserProfileInfo = UserProfileInfo(None, None, None, None)
val EmptyUserProfileInfoFuture: Future[UserProfileInfo] = Future.value(EmptyUserProfileInfo)
}
/**
* FutureArrow which fetches user profile info
* It should be run in parallel with the main pipeline which fetches and hydrates CandidateTweets
*/
class UserProfileInfoTransform(handler: FailOpenHandler, gizmoduckClient: GizmoduckClient)
extends FutureArrow[RecapQuery, UserProfileInfo] {
import UserProfileInfoTransform._
override def apply(request: RecapQuery): Future[UserProfileInfo] = {
handler {
gizmoduckClient.getProfileInfo(request.userId).map { profileInfoOpt =>
profileInfoOpt.getOrElse(EmptyUserProfileInfo)
}
} { _: Throwable => EmptyUserProfileInfoFuture }
}
}