mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-01 00:38:46 +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.
61 lines
1.9 KiB
Scala
61 lines
1.9 KiB
Scala
package com.twitter.recosinjector.edges
|
|
|
|
import com.twitter.finagle.stats.StatsReceiver
|
|
import com.twitter.recos.util.Action
|
|
import com.twitter.recosinjector.util.TweetFavoriteEventDetails
|
|
import com.twitter.util.Future
|
|
|
|
class TimelineEventToUserTweetEntityGraphBuilder(
|
|
userTweetEntityEdgeBuilder: UserTweetEntityEdgeBuilder
|
|
)(
|
|
override implicit val statsReceiver: StatsReceiver)
|
|
extends EventToMessageBuilder[TweetFavoriteEventDetails, UserTweetEntityEdge] {
|
|
|
|
private val numFavEdgeCounter = statsReceiver.counter("num_favorite_edge")
|
|
private val numUnfavEdgeCounter = statsReceiver.counter("num_unfavorite_edge")
|
|
|
|
override def shouldProcessEvent(event: TweetFavoriteEventDetails): Future[Boolean] = {
|
|
Future(true)
|
|
}
|
|
|
|
override def buildEdges(details: TweetFavoriteEventDetails): Future[Seq[UserTweetEntityEdge]] = {
|
|
val engagement = details.userTweetEngagement
|
|
val tweetDetails = engagement.tweetDetails
|
|
|
|
val entitiesMapFut = userTweetEntityEdgeBuilder.getEntitiesMapAndUpdateCache(
|
|
tweetId = engagement.tweetId,
|
|
tweetDetails = tweetDetails
|
|
)
|
|
|
|
entitiesMapFut
|
|
.map { entitiesMap =>
|
|
UserTweetEntityEdge(
|
|
sourceUser = engagement.engageUserId,
|
|
targetTweet = engagement.tweetId,
|
|
action = engagement.action,
|
|
metadata = engagement.engagementTimeMillis,
|
|
cardInfo = engagement.tweetDetails.map(_.cardInfo.toByte),
|
|
entitiesMap = entitiesMap,
|
|
tweetDetails = tweetDetails
|
|
)
|
|
}
|
|
.map { edge =>
|
|
edge match {
|
|
case fav if fav.action == Action.Favorite =>
|
|
numFavEdgeCounter.incr()
|
|
case unfav if unfav.action == Action.Unfavorite =>
|
|
numUnfavEdgeCounter.incr()
|
|
case _ =>
|
|
}
|
|
Seq(edge)
|
|
}
|
|
}
|
|
|
|
override def filterEdges(
|
|
event: TweetFavoriteEventDetails,
|
|
edges: Seq[UserTweetEntityEdge]
|
|
): Future[Seq[UserTweetEntityEdge]] = {
|
|
Future(edges)
|
|
}
|
|
}
|