From c7be674b84699e2011574b43311d880449d90b0f Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Fri, 25 Feb 2022 21:35:23 -0500 Subject: [PATCH] small performance optimization (#3426) --- .../java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index e117fe997ff..507428054b0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -194,7 +194,6 @@ public abstract class BaseHapiFhirDao extends BaseStora public static final long INDEX_STATUS_INDEXING_FAILED = 2L; public static final String NS_JPA_PROFILE = "https://github.com/hapifhir/hapi-fhir/ns/jpa/profile"; private static final Logger ourLog = LoggerFactory.getLogger(BaseHapiFhirDao.class); - private static final Map ourRetrievalContexts = new HashMap<>(); private static boolean ourValidationDisabledForUnitTest; private static boolean ourDisableIncrementOnUpdateForUnitTest = false; @@ -391,14 +390,10 @@ public abstract class BaseHapiFhirDao extends BaseStora public FhirContext getContext(FhirVersionEnum theVersion) { Validate.notNull(theVersion, "theVersion must not be null"); - synchronized (ourRetrievalContexts) { - FhirContext retVal = ourRetrievalContexts.get(theVersion); - if (retVal == null) { - retVal = new FhirContext(theVersion); - ourRetrievalContexts.put(theVersion, retVal); - } - return retVal; + if (theVersion == myFhirContext.getVersion().getVersion()) { + return myFhirContext; } + return FhirContext.forCached(theVersion); } /** @@ -434,7 +429,7 @@ public abstract class BaseHapiFhirDao extends BaseStora /** * Gets the tag defined by the fed in values, or saves it if it does not * exist. - * + *

* Can also throw an InternalErrorException if something bad happens. */ private TagDefinition getOrCreateTag(TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel) {