From 0917e50b70b7f19ca12a7e2f4963524220fea30a Mon Sep 17 00:00:00 2001 From: William Woods Date: Mon, 3 Apr 2023 07:11:21 +0000 Subject: [PATCH] Refactored code for performance and readability --- .../common/clients/geoduck/UserLocationFetcher.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/clients/geoduck/UserLocationFetcher.scala b/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/clients/geoduck/UserLocationFetcher.scala index d83208033..b279118cb 100644 --- a/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/clients/geoduck/UserLocationFetcher.scala +++ b/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/clients/geoduck/UserLocationFetcher.scala @@ -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.stitch.Stitch @@ -8,6 +10,7 @@ class UserLocationFetcher @Inject() ( locationServiceClient: LocationServiceClient, reverseGeocodeClient: ReverseGeocodeClient, statsReceiver: StatsReceiver) { + private val stats = statsReceiver.scope("user_location_fetcher") def getGeohashAndCountryCode(userId: Option[Long], ipAddress: Option[String]): Stitch[Option[GeohashAndCountryCode]] = { @@ -26,7 +29,7 @@ class UserLocationFetcher @Inject() ( } Stitch.join(lscLocationStitch, ipLocationStitch).map { - case (lscLocation, ipLocation) => + case (lscLocation, ipLocation) => (lscLocation.flatMap(_.geohash).orElse(ipLocation.flatMap(_.geohash)), lscLocation.flatMap(_.countryCode).orElse(ipLocation.flatMap(_.countryCode))) match { case (Some(geohash), Some(countryCode)) => @@ -34,7 +37,7 @@ class UserLocationFetcher @Inject() ( case _ => stats.counter("empty").incr() None - } + } } } -} +} \ No newline at end of file