From c31900b82743ff8fdbeff0a2d9a27f9b9b1fc7fb Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sun, 25 Oct 2015 12:18:21 -0400 Subject: [PATCH] JPA performance tweaks: Avoid unneccesary fulltext index pass during transaction and tag lookup --- .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 5 +- .../ca/uhn/fhir/jpa/entity/ResourceTable.java | 4 +- .../search/IndexNonDeletedInterceptor.java | 7 +- .../uhn/fhir/jpa/config/TestDstu2Config.java | 2 +- .../dao/FhirResourceDaoDstu2SearchFtTest.java | 65 +++++++++++++++++++ hapi-fhir-structures-hl7org-dstu2/.classpath | 2 +- 6 files changed, 76 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 3a9292b9323..796c8613a2d 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 @@ -684,6 +684,8 @@ public abstract class BaseHapiFhirDao implements IDao { Set allDefs = new HashSet(); + theEntity.setHasTags(false); + TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); if (tagList != null) { for (Tag next : tagList) { @@ -726,9 +728,6 @@ public abstract class BaseHapiFhirDao implements IDao { } } } - if (theEntity.getTags().size() == 0) { - theEntity.setHasTags(false); - } String title = ResourceMetadataKeyEnum.TITLE.get(theResource); if (title != null && title.length() > BaseHasResource.MAX_TITLE_LENGTH) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceTable.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceTable.java index a75fcb390d0..f82a7c0320c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceTable.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceTable.java @@ -35,14 +35,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Index; -import javax.persistence.Lob; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Indexed; -import org.hibernate.search.annotations.IndexedEmbedded; import ca.uhn.fhir.jpa.search.IndexNonDeletedInterceptor; import ca.uhn.fhir.model.primitive.IdDt; @@ -50,7 +48,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; //@formatter:off -@Indexed(/*interceptor=IndexNonDeletedInterceptor.class*/) +@Indexed(interceptor=IndexNonDeletedInterceptor.class) @Entity @Table(name = "HFJ_RESOURCE", uniqueConstraints = {}, indexes= { @Index(name = "IDX_RES_DATE", columnList="RES_UPDATED"), diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/IndexNonDeletedInterceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/IndexNonDeletedInterceptor.java index 3209b63c377..ebf9077ad5d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/IndexNonDeletedInterceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/IndexNonDeletedInterceptor.java @@ -33,13 +33,18 @@ public class IndexNonDeletedInterceptor implements EntityIndexingInterceptorDIVAAA"); + patient.addName().addGiven("NAMEAAA"); + IIdType pId1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_TEXT, new StringParam("DIVAAA")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + + /* + * Update but don't reindex + */ + + patient = new Patient(); + patient.setId(pId1); + patient.getText().setDiv("
DIVBBB
"); + patient.addName().addGiven("NAMEBBB"); + myPatientDao.update(patient, null, false); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + map = new SearchParameterMap(); + map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(contains(pId1))); + + myPatientDao.update(patient, null, true); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_CONTENT, new StringParam("NAMEAAA")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), empty()); + + map = new SearchParameterMap(); + map.add(Patient.SP_NAME, new StringParam("NAMEBBB")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + + map = new SearchParameterMap(); + map.add(Constants.PARAM_TEXT, new StringParam("DIVBBB")); + assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); + + + } + + + @Test public void testSearchWithChainedParams() { String methodName = "testSearchWithChainedParams"; diff --git a/hapi-fhir-structures-hl7org-dstu2/.classpath b/hapi-fhir-structures-hl7org-dstu2/.classpath index 5e078287bc2..f87998e1d5c 100644 --- a/hapi-fhir-structures-hl7org-dstu2/.classpath +++ b/hapi-fhir-structures-hl7org-dstu2/.classpath @@ -12,7 +12,7 @@ - +