the-algorithm/home-mixer/server/src/main/scala/com/twitter/home_mixer/functional_component/gate/MinCachedTweetsGate.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

35 lines
1.4 KiB
Scala

package com.twitter.home_mixer.functional_component.gate
import com.twitter.home_mixer.functional_component.gate.MinCachedTweetsGate.identifierSuffix
import com.twitter.home_mixer.util.CachedScoredTweetsHelper
import com.twitter.product_mixer.core.functional_component.gate.Gate
import com.twitter.product_mixer.core.model.common.identifier.CandidatePipelineIdentifier
import com.twitter.product_mixer.core.model.common.identifier.GateIdentifier
import com.twitter.product_mixer.core.pipeline.PipelineQuery
import com.twitter.stitch.Stitch
import com.twitter.timelines.configapi.Param
case class MinCachedTweetsGate(
candidatePipelineIdentifier: CandidatePipelineIdentifier,
minCachedTweetsParam: Param[Int])
extends Gate[PipelineQuery] {
override val identifier: GateIdentifier =
GateIdentifier(candidatePipelineIdentifier + identifierSuffix)
override def shouldContinue(query: PipelineQuery): Stitch[Boolean] = {
val minCachedTweets = query.params(minCachedTweetsParam)
val cachedScoredTweets =
query.features.map(CachedScoredTweetsHelper.unseenCachedScoredTweets).getOrElse(Seq.empty)
val numCachedTweets = cachedScoredTweets.count { tweet =>
tweet.candidatePipelineIdentifier.exists(
CandidatePipelineIdentifier(_).equals(candidatePipelineIdentifier))
}
Stitch.value(numCachedTweets < minCachedTweets)
}
}
object MinCachedTweetsGate {
val identifierSuffix = "MinCachedTweets"
}