Skip to content

Commit

Permalink
Merge pull request #2320 from hongwei1/develop
Browse files Browse the repository at this point in the history
bugfix/fixed the cacheKey for getResourceDocs
  • Loading branch information
simonredfern authored Nov 13, 2023
2 parents 303b56f + 56cd811 commit e4f1b85
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,16 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
}
requestedApiVersion <- NewStyle.function.tryons(s"$InvalidApiVersionString $requestedApiVersionString", 400, callContext) {ApiVersionUtils.valueOf(requestedApiVersionString)}
_ <- Helper.booleanToFuture(s"$ApiVersionNotSupported $requestedApiVersionString", 400, callContext)(versionIsAllowed(requestedApiVersion))
cacheKey = (locale.toString + tags + partialFunctions+ contentParam+ isVersion4OrHigher).intern()
cacheKey = APIUtil.createResourceDocCacheKey(
None,
requestedApiVersionString,
tags,
partialFunctions,
locale,
contentParam,
apiCollectionIdParam,
Some(isVersion4OrHigher),
Some(isStaticResource))
json <- locale match {
case _ if (apiCollectionIdParam.isDefined) =>
val operationIds = MappedApiCollectionEndpointsProvider.getApiCollectionEndpoints(apiCollectionIdParam.getOrElse("")).map(_.operationId).map(getObpFormatOperationId)
Expand Down Expand Up @@ -637,8 +646,16 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
)
}
requestedApiVersion <- NewStyle.function.tryons(s"$InvalidApiVersionString $requestedApiVersionString", 400, callContext) {ApiVersionUtils.valueOf(requestedApiVersionString)}
cacheKey = (locale.toString + tags + partialFunctions+ contentParam+ false).intern()

cacheKey = APIUtil.createResourceDocCacheKey(
Some(bankId),
requestedApiVersionString,
tags,
partialFunctions,
locale,
contentParam,
apiCollectionIdParam,
None,
None)
json <- NewStyle.function.tryons(s"$UnknownError Can not create dynamic resource docs.", 400, callContext) {
val cacheValueFromRedis = Caching.getDynamicResourceDocCache(cacheKey)
if (cacheValueFromRedis.isDefined) {
Expand Down Expand Up @@ -706,7 +723,16 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
_ <- Helper.booleanToFuture(failMsg = s"$ApiVersionNotSupported Current Version is $requestedApiVersionString", cc=cc.callContext) {
versionIsAllowed(requestedApiVersion)
}
cacheKey = requestedApiVersionString + resourceDocTags+ partialFunctions
cacheKey = APIUtil.createResourceDocCacheKey(
None,
requestedApiVersionString,
resourceDocTags,
partialFunctions,
None,
None,
None,
None,
None)
staticJson <- NewStyle.function.tryons(s"$UnknownError Can not convert internal swagger file.", 400, cc.callContext) {
val cacheValueFromRedis = Caching.getStaticSwaggerDocCache(cacheKey)

Expand Down
24 changes: 23 additions & 1 deletion obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import com.alibaba.ttl.internal.javassist.CannotCompileException
import com.github.dwickern.macros.NameOf.{nameOf, nameOfType}
import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
import com.openbankproject.commons.model.enums.{PemCertificateRole, StrongCustomerAuthentication}
import com.openbankproject.commons.model.enums.{ContentParam, PemCertificateRole, StrongCustomerAuthentication}
import com.openbankproject.commons.model.{Customer, UserAuthContext, _}
import com.openbankproject.commons.util.Functions.Implicits._
import com.openbankproject.commons.util.Functions.Memo
Expand Down Expand Up @@ -4872,4 +4872,26 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
)
}

def createResourceDocCacheKey(
bankId : Option[String],
requestedApiVersionString: String,
tags: Option[List[ResourceDocTag]],
partialFunctions: Option[List[String]],
locale: Option[String],
contentParam: Option[ContentParam],
apiCollectionIdParam: Option[String],
isVersion4OrHigher: Option[Boolean],
isStaticResource: Option[Boolean],
) = (requestedApiVersionString
+ bankId
+ tags
+ partialFunctions
+ locale.toString
+ contentParam
+ apiCollectionIdParam
+ isVersion4OrHigher
+ isStaticResource
).intern()


}
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ object JSONFactory1_4_0 extends MdcLoggable{
val userDefinedEndpointTags = getAllEndpointTagsBox(rd.operationId).map(endpointTag =>ResourceDocTag(endpointTag.tagName))
val resourceDocWithUserDefinedEndpointTags: ResourceDoc = rd.copy(tags = userDefinedEndpointTags++ rd.tags)

val cacheKey = (resourceDocWithUserDefinedEndpointTags.operationId + locale).intern()
val cacheKey = (resourceDocWithUserDefinedEndpointTags.operationId + locale + isVersion4OrHigher).intern()
val cacheValueFromRedis = Caching.getLocalisedResourceDocCache(cacheKey)

if(cacheValueFromRedis.isDefined){
Expand Down

0 comments on commit e4f1b85

Please sign in to comment.