11package de .symeda .sormas .backend .patch .partial_retrieval ;
22
3+ import java .util .HashMap ;
34import java .util .List ;
45import java .util .Map ;
56import java .util .Optional ;
@@ -65,6 +66,8 @@ public PartialRetrievalResponse retrievePartial(PartialRetrievalRequest request)
6566
6667 CaseDataDto caseData = businessDtoFacade .getCaseDataDto (request .getCaseUuid ());
6768
69+ Map <String , Optional <EntityDto >> beanCache = new HashMap <>();
70+
6871 List <Tuple <String , Tuple <FieldInfo , PartialRetrievalFailureCause >>> results =
6972 patchFieldHelper .extractFieldTuples (request .getFieldsToRetrieve (), businessDtoFacade .fetchablePrefixes ()).stream ().map (tuple -> {
7073
@@ -86,7 +89,7 @@ public PartialRetrievalResponse retrievePartial(PartialRetrievalRequest request)
8689 String physicalPathName = pathWithoutAlias .substring (pathWithoutAlias .indexOf ('.' ) + 1 );
8790
8891 String aliasPath = pathAliasHelper .toAliasPath (pathWithoutAlias );
89- Optional <EntityDto > adequateBean = getAdequateBean (pathWithoutAlias , caseData );
92+ Optional <EntityDto > adequateBean = getAdequateBean (pathWithoutAlias , caseData , beanCache );
9093
9194 if (adequateBean .isEmpty ()) {
9295 return Tuple .of (originalFieldName , new Tuple <>((FieldInfo ) null , PartialRetrievalFailureCause .ENTITY_COULD_NOT_BE_FOUND ));
@@ -147,7 +150,10 @@ public DisplayablePartialRetrievalResponse retrievePartialForDisplay(PartialRetr
147150 .collect (Collectors .toMap (Map .Entry ::getKey , entry -> I18nProperties .getEnumCaption (entry .getValue ()))));
148151 }
149152
150- private Optional <EntityDto > getAdequateBean (@ NotNull String aliasPath , @ NotNull CaseDataDto caseData ) {
153+ private Optional <EntityDto > getAdequateBean (
154+ @ NotNull String aliasPath ,
155+ @ NotNull CaseDataDto caseData ,
156+ @ NotNull Map <String , Optional <EntityDto >> beanCache ) {
151157
152158 int i = aliasPath .indexOf ("." );
153159
@@ -156,19 +162,21 @@ private Optional<EntityDto> getAdequateBean(@NotNull String aliasPath, @NotNull
156162 if (CaseDataDto .I18N_PREFIX .equals (prefix )) {
157163 return Optional .of (caseData );
158164 } else {
159- List <? extends EntityDto > entityDtos = businessDtoFacade .fetchByI18nName (prefix , caseData );
165+ return beanCache .computeIfAbsent (prefix , prefixCandidate -> {
166+ List <? extends EntityDto > entityDtos = businessDtoFacade .fetchByI18nName (prefixCandidate , caseData );
160167
161- int entitiesSize = CollectionUtils .size (entityDtos );
168+ int entitiesSize = CollectionUtils .size (entityDtos );
162169
163- if (entitiesSize == 0 ) {
164- return Optional .empty ();
165- }
170+ if (entitiesSize == 0 ) {
171+ return Optional .empty ();
172+ }
166173
167- if (entitiesSize != 1 ) {
168- logger .warn ("Only first element is supported for now: [{}], was: [{}]" , aliasPath , entitiesSize );
169- }
174+ if (entitiesSize != 1 ) {
175+ logger .warn ("Only first element is supported for now: [{}], was: [{}]" , aliasPath , entitiesSize );
176+ }
170177
171- return Optional .ofNullable (entityDtos ).map (actualEntities -> actualEntities .get (0 ));
178+ return Optional .ofNullable (entityDtos ).map (actualEntities -> actualEntities .get (0 ));
179+ });
172180 }
173181 }
174182
0 commit comments