Skip to content

Commit

Permalink
Merge pull request #2348 from hongwei1/develop
Browse files Browse the repository at this point in the history
bugfix/move the future out of the cache
  • Loading branch information
simonredfern authored Dec 6, 2023
2 parents d505b3f + c0f354f commit 03a4f39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3056,15 +3056,15 @@ object NewStyle extends MdcLoggable{

private[this] val endpointMappingTTL = APIUtil.getPropsValue(s"endpointMapping.cache.ttl.seconds", "0").toInt

def getEndpointMappings(bankId: Option[String], callContext: Option[CallContext]): OBPReturnType[List[EndpointMappingT]] = {
def getEndpointMappings(bankId: Option[String], callContext: Option[CallContext]): OBPReturnType[List[EndpointMappingT]] = Future{
import scala.concurrent.duration._

validateBankId(bankId, callContext)

var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
CacheKeyFromArguments.buildCacheKey {
Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(endpointMappingTTL second) {
Future{(EndpointMappingProvider.endpointMappingProvider.vend.getAllEndpointMappings(bankId), callContext)}
{(EndpointMappingProvider.endpointMappingProvider.vend.getAllEndpointMappings(bankId), callContext)}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions obp-api/src/main/scala/code/metrics/MappedMetrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
}

// TODO Cache this as long as fromDate and toDate are in the past (before now)
override def getTopApisFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopApi]]] = {
override def getTopApisFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopApi]]] = Future{
/**
* Please note that "var cacheKey = (randomUUID().toString, randomUUID().toString, randomUU
* is just a temporary value field with UUID values in order to prevent any ambiguity.
Expand All @@ -369,7 +369,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
*/
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
CacheKeyFromArguments.buildCacheKey {Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(cachedTopApis seconds){
Future{
{
val fromDate = queryParams.collect { case OBPFromDate(value) => value }.headOption
val toDate = queryParams.collect { case OBPToDate(value) => value }.headOption
val consumerId = queryParams.collect { case OBPConsumerId(value) => value }.headOption.flatMap(consumerIdToPrimaryKey)
Expand Down Expand Up @@ -440,7 +440,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
}}

// TODO Cache this as long as fromDate and toDate are in the past (before now)
override def getTopConsumersFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopConsumer]]] = {
override def getTopConsumersFuture(queryParams: List[OBPQueryParam]): Future[Box[List[TopConsumer]]] = Future {
/**
* Please note that "var cacheKey = (randomUUID().toString, randomUUID().toString, randomUU
* is just a temporary value field with UUID values in order to prevent any ambiguity.
Expand All @@ -449,7 +449,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
*/
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
CacheKeyFromArguments.buildCacheKey {Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(cachedTopConsumers seconds){
Future {

val fromDate = queryParams.collect { case OBPFromDate(value) => value }.headOption
val toDate = queryParams.collect { case OBPToDate(value) => value }.headOption
val consumerId = queryParams.collect { case OBPConsumerId(value) => value }.headOption.flatMap(consumerIdToPrimaryKey)
Expand Down Expand Up @@ -519,7 +519,7 @@ object MappedMetrics extends APIMetrics with MdcLoggable{
}
tryo(result)
}
}}}
}}

}

Expand Down

0 comments on commit 03a4f39

Please sign in to comment.