mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-27 13:36:03 +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.
47 lines
1.8 KiB
Scala
47 lines
1.8 KiB
Scala
package com.twitter.home_mixer.functional_component.feature_hydrator
|
|
|
|
import com.twitter.product_mixer.core.feature.Feature
|
|
import com.twitter.product_mixer.core.feature.featuremap.FeatureMap
|
|
import com.twitter.product_mixer.core.feature.featuremap.FeatureMapBuilder
|
|
import com.twitter.product_mixer.core.functional_component.feature_hydrator.QueryFeatureHydrator
|
|
import com.twitter.product_mixer.core.model.common.identifier.FeatureHydratorIdentifier
|
|
import com.twitter.product_mixer.core.pipeline.PipelineQuery
|
|
import com.twitter.socialgraph.{thriftscala => sg}
|
|
import com.twitter.stitch.Stitch
|
|
import com.twitter.stitch.socialgraph.{SocialGraph => SocialGraphStitchClient}
|
|
import javax.inject.Inject
|
|
import javax.inject.Singleton
|
|
|
|
object SGSFollowedUsersFeature extends Feature[PipelineQuery, Seq[Long]]
|
|
|
|
@Singleton
|
|
case class SGSFollowedUsersQueryFeatureHydrator @Inject() (
|
|
socialGraphStitchClient: SocialGraphStitchClient)
|
|
extends QueryFeatureHydrator[PipelineQuery] {
|
|
|
|
override val identifier: FeatureHydratorIdentifier =
|
|
FeatureHydratorIdentifier("SGSFollowedUsers")
|
|
|
|
override val features: Set[Feature[_, _]] = Set(SGSFollowedUsersFeature)
|
|
|
|
private val SocialGraphLimit = 14999
|
|
|
|
override def hydrate(query: PipelineQuery): Stitch[FeatureMap] = {
|
|
val userId = query.getRequiredUserId
|
|
|
|
val request = sg.IdsRequest(
|
|
relationships = Seq(
|
|
sg.SrcRelationship(userId, sg.RelationshipType.Following, hasRelationship = true),
|
|
sg.SrcRelationship(userId, sg.RelationshipType.Muting, hasRelationship = false)
|
|
),
|
|
pageRequest = Some(sg.PageRequest(count = Some(SocialGraphLimit)))
|
|
)
|
|
|
|
socialGraphStitchClient
|
|
.ids(request).map(_.ids)
|
|
.map { followedUsers =>
|
|
FeatureMapBuilder().add(SGSFollowedUsersFeature, followedUsers).build()
|
|
}
|
|
}
|
|
}
|