the-algorithm/home-mixer/server/src/main/scala/com/twitter/home_mixer/store/RealGraphInNetworkScoresStore.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.5 KiB
Scala

package com.twitter.home_mixer.store
import com.twitter.bijection.Injection
import com.twitter.home_mixer.store.ManhattanRealGraphKVDescriptor._
import com.twitter.stitch.Stitch
import com.twitter.storage.client.manhattan.bijections.Bijections
import com.twitter.storage.client.manhattan.bijections.Bijections.BinaryScalaInjection
import com.twitter.storage.client.manhattan.kv.ManhattanKVEndpoint
import com.twitter.storage.client.manhattan.kv.impl.ReadOnlyKeyDescriptor
import com.twitter.storage.client.manhattan.kv.impl.ValueDescriptor
import com.twitter.storehaus.ReadableStore
import com.twitter.util.Future
import com.twitter.wtf.candidate.{thriftscala => wtf}
object ManhattanRealGraphKVDescriptor {
implicit val byteArray2Buf = Bijections.BytesBijection
val realGraphDatasetName = "real_graph_scores_in"
val keyInjection = Injection.connect[Long, Array[Byte]].andThen(Bijections.BytesInjection)
val keyDesc = ReadOnlyKeyDescriptor(keyInjection)
val valueDesc = ValueDescriptor(BinaryScalaInjection(wtf.CandidateSeq))
val realGraphDatasetKey = keyDesc.withDataset(realGraphDatasetName)
}
/**
* Hydrates real graph in network scores for a viewer
*/
class RealGraphInNetworkScoresStore(manhattanKVEndpoint: ManhattanKVEndpoint)
extends ReadableStore[Long, Seq[wtf.Candidate]] {
override def get(viewerId: Long): Future[Option[Seq[wtf.Candidate]]] = Stitch
.run(manhattanKVEndpoint.get(realGraphDatasetKey.withPkey(viewerId), valueDesc))
.map(_.map(mhResponse => mhResponse.contents.candidates))
}