mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 14:48:54 +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.
32 lines
1.3 KiB
Scala
32 lines
1.3 KiB
Scala
package com.twitter.timelineranker.common
|
|
|
|
import com.twitter.servo.util.FutureArrow
|
|
import com.twitter.timelineranker.core.CandidateEnvelope
|
|
import com.twitter.util.Future
|
|
|
|
/**
|
|
* Transform that explicitly hydrates candidate tweets and fetches source tweets in parallel
|
|
* and then joins the results back into the original Envelope
|
|
* @param candidateTweetHydration Pipeline that hydrates candidate tweets
|
|
* @param sourceTweetHydration Pipeline that fetches and hydrates source tweets
|
|
*/
|
|
class HydrateTweetsAndSourceTweetsInParallelTransform(
|
|
candidateTweetHydration: FutureArrow[CandidateEnvelope, CandidateEnvelope],
|
|
sourceTweetHydration: FutureArrow[CandidateEnvelope, CandidateEnvelope])
|
|
extends FutureArrow[CandidateEnvelope, CandidateEnvelope] {
|
|
override def apply(envelope: CandidateEnvelope): Future[CandidateEnvelope] = {
|
|
Future
|
|
.join(
|
|
candidateTweetHydration(envelope),
|
|
sourceTweetHydration(envelope)
|
|
).map {
|
|
case (candidateTweetEnvelope, sourceTweetEnvelope) =>
|
|
envelope.copy(
|
|
hydratedTweets = candidateTweetEnvelope.hydratedTweets,
|
|
sourceSearchResults = sourceTweetEnvelope.sourceSearchResults,
|
|
sourceHydratedTweets = sourceTweetEnvelope.sourceHydratedTweets
|
|
)
|
|
}
|
|
}
|
|
}
|