mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 18:21:51 +01:00
Refactored code for performance and readability
This commit is contained in:
parent
ef04e156fd
commit
0917e50b70
@ -1,3 +1,5 @@
|
|||||||
|
package com.twitter.follow_recommendations.common.clients.geoduck
|
||||||
|
import com.twitter.finagle.stats.StatsReceiver
|
||||||
import com.twitter.follow_recommendations.common.models.GeohashAndCountryCode
|
import com.twitter.follow_recommendations.common.models.GeohashAndCountryCode
|
||||||
import com.twitter.stitch.Stitch
|
import com.twitter.stitch.Stitch
|
||||||
|
|
||||||
@ -8,6 +10,7 @@ class UserLocationFetcher @Inject() (
|
|||||||
locationServiceClient: LocationServiceClient,
|
locationServiceClient: LocationServiceClient,
|
||||||
reverseGeocodeClient: ReverseGeocodeClient,
|
reverseGeocodeClient: ReverseGeocodeClient,
|
||||||
statsReceiver: StatsReceiver) {
|
statsReceiver: StatsReceiver) {
|
||||||
|
|
||||||
private val stats = statsReceiver.scope("user_location_fetcher")
|
private val stats = statsReceiver.scope("user_location_fetcher")
|
||||||
|
|
||||||
def getGeohashAndCountryCode(userId: Option[Long], ipAddress: Option[String]): Stitch[Option[GeohashAndCountryCode]] = {
|
def getGeohashAndCountryCode(userId: Option[Long], ipAddress: Option[String]): Stitch[Option[GeohashAndCountryCode]] = {
|
||||||
@ -26,7 +29,7 @@ class UserLocationFetcher @Inject() (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Stitch.join(lscLocationStitch, ipLocationStitch).map {
|
Stitch.join(lscLocationStitch, ipLocationStitch).map {
|
||||||
case (lscLocation, ipLocation) =>
|
case (lscLocation, ipLocation) =>
|
||||||
(lscLocation.flatMap(_.geohash).orElse(ipLocation.flatMap(_.geohash)),
|
(lscLocation.flatMap(_.geohash).orElse(ipLocation.flatMap(_.geohash)),
|
||||||
lscLocation.flatMap(_.countryCode).orElse(ipLocation.flatMap(_.countryCode))) match {
|
lscLocation.flatMap(_.countryCode).orElse(ipLocation.flatMap(_.countryCode))) match {
|
||||||
case (Some(geohash), Some(countryCode)) =>
|
case (Some(geohash), Some(countryCode)) =>
|
||||||
@ -34,7 +37,7 @@ class UserLocationFetcher @Inject() (
|
|||||||
case _ =>
|
case _ =>
|
||||||
stats.counter("empty").incr()
|
stats.counter("empty").incr()
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user