mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-27 21:46:04 +02:00
![twitter-team](/assets/img/avatar_default.png)
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.
35 lines
1.5 KiB
Scala
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))
|
|
}
|