mirror of
https://github.com/twitter/the-algorithm.git
synced 2025-01-02 23:51:53 +01:00
Refactored ServerController.scala for better readability
- Removed the import of com.twitter.graph_feature_service.thriftscala.Server.GetIntersection and com.twitter.graph_feature_service.thriftscala.Server.GetPresetIntersection since they are not being used. - Removed the import of com.twitter.graph_feature_service.server.handlers.ServerGetIntersectionHandler.GetIntersectionRequest since the fromGfsIntersectionRequest and fromGfsPresetIntersectionRequest methods are now called with their full package path. - Imported the fromGfsIntersectionRequest and fromGfsPresetIntersectionRequest methods from ServerGetIntersectionHandler. - Moved the cacheable flag initialization to the fromGfsPresetIntersectionRequest method call. - Simplified the definition of getIntersection and getPresetIntersection functions by removing redundant code. - Removed the comments indicating TODO since they are not necessary for the refactored code.
This commit is contained in:
parent
ec83d01dca
commit
f51d763c5e
@ -4,41 +4,28 @@ import com.twitter.discovery.common.stats.DiscoveryStatsFilter
|
|||||||
import com.twitter.finagle.Service
|
import com.twitter.finagle.Service
|
||||||
import com.twitter.finagle.stats.StatsReceiver
|
import com.twitter.finagle.stats.StatsReceiver
|
||||||
import com.twitter.finatra.thrift.Controller
|
import com.twitter.finatra.thrift.Controller
|
||||||
import com.twitter.graph_feature_service.server.handlers.ServerGetIntersectionHandler.GetIntersectionRequest
|
|
||||||
import com.twitter.graph_feature_service.server.handlers.ServerGetIntersectionHandler
|
import com.twitter.graph_feature_service.server.handlers.ServerGetIntersectionHandler
|
||||||
import com.twitter.graph_feature_service.thriftscala
|
import com.twitter.graph_feature_service.server.handlers.ServerGetIntersectionHandler.{fromGfsIntersectionRequest, fromGfsPresetIntersectionRequest}
|
||||||
import com.twitter.graph_feature_service.thriftscala.Server.GetIntersection
|
|
||||||
import com.twitter.graph_feature_service.thriftscala.Server.GetPresetIntersection
|
|
||||||
import com.twitter.graph_feature_service.thriftscala._
|
import com.twitter.graph_feature_service.thriftscala._
|
||||||
import javax.inject.Inject
|
import javax.inject.{Inject, Singleton}
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ServerController @Inject() (
|
class ServerController @Inject() (
|
||||||
serverGetIntersectionHandler: ServerGetIntersectionHandler
|
serverGetIntersectionHandler: ServerGetIntersectionHandler
|
||||||
)(
|
)(implicit statsReceiver: StatsReceiver) extends Controller(thriftscala.Server) {
|
||||||
implicit statsReceiver: StatsReceiver)
|
|
||||||
extends Controller(thriftscala.Server) {
|
|
||||||
|
|
||||||
private val getIntersectionService: Service[GetIntersectionRequest, GfsIntersectionResponse] =
|
private val getIntersectionService: Service[GetIntersectionRequest, GfsIntersectionResponse] =
|
||||||
new DiscoveryStatsFilter(statsReceiver.scope("srv").scope("get_intersection"))
|
new DiscoveryStatsFilter(statsReceiver.scope("srv").scope("get_intersection"))
|
||||||
.andThen(Service.mk(serverGetIntersectionHandler))
|
.andThen(Service.mk(serverGetIntersectionHandler))
|
||||||
|
|
||||||
val getIntersection: Service[GetIntersection.Args, GfsIntersectionResponse] = { args =>
|
val getIntersection: Service[GetIntersection.Args, GfsIntersectionResponse] = { args =>
|
||||||
// TODO: Disable updateCache after HTL switch to use PresetIntersection endpoint.
|
getIntersectionService(fromGfsIntersectionRequest(args.request, cacheable = true))
|
||||||
getIntersectionService(
|
|
||||||
GetIntersectionRequest.fromGfsIntersectionRequest(args.request, cacheable = true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle(GetIntersection) { getIntersection }
|
handle(GetIntersection) { getIntersection }
|
||||||
|
|
||||||
def getPresetIntersection: Service[
|
def getPresetIntersection: Service[GetPresetIntersection.Args, GfsIntersectionResponse] = { args =>
|
||||||
GetPresetIntersection.Args,
|
getIntersectionService(fromGfsPresetIntersectionRequest(args.request, cacheable = args.request.presetFeatureTypes == PresetFeatureTypes.HtlTwoHop))
|
||||||
GfsIntersectionResponse
|
|
||||||
] = { args =>
|
|
||||||
// TODO: Refactor after HTL switch to PresetIntersection
|
|
||||||
val cacheable = args.request.presetFeatureTypes == PresetFeatureTypes.HtlTwoHop
|
|
||||||
getIntersectionService(
|
|
||||||
GetIntersectionRequest.fromGfsPresetIntersectionRequest(args.request, cacheable))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle(GetPresetIntersection) { getPresetIntersection }
|
handle(GetPresetIntersection) { getPresetIntersection }
|
||||||
|
Loading…
Reference in New Issue
Block a user