From 3a7ea64a40abe0fda3d59416bdc5343ba39ae78d Mon Sep 17 00:00:00 2001 From: jmarchionatto <60409882+jmarchionatto@users.noreply.github.com> Date: Mon, 2 May 2022 14:52:11 -0400 Subject: [PATCH] As a temporary palliative until we refactor async search, disallow scrolling less than 50 (#3576) Co-authored-by: juan.marchionatto --- .../fhir/jpa/dao/FulltextSearchSvcImpl.java | 4 +-- ...esourceDaoR4SearchWithElasticSearchIT.java | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java index 9a5909023be..0f588606dbf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FulltextSearchSvcImpl.java @@ -37,7 +37,6 @@ import ca.uhn.fhir.jpa.search.autocomplete.ValueSetAutocompleteOptions; import ca.uhn.fhir.jpa.search.autocomplete.ValueSetAutocompleteSearch; import ca.uhn.fhir.jpa.search.builder.ISearchQueryExecutor; import ca.uhn.fhir.jpa.search.builder.SearchQueryExecutors; -import ca.uhn.fhir.jpa.search.builder.sql.SearchQueryExecutor; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor; import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams; @@ -151,7 +150,8 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc { private SearchScroll getSearchScroll(String theResourceType, SearchParameterMap theParams, ResourcePersistentId theReferencingPid) { - int scrollSize = 50; + // disallow scroll size lees than 50 until we fix scrolling performance + int scrollSize = theParams.getCount() == null ? 50 : Math.max(50, theParams.getCount()); if (theParams.getCount()!=null) { scrollSize = theParams.getCount(); } diff --git a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java index bab3e47ebf9..2c361d9123e 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java +++ b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java @@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; import ca.uhn.fhir.storage.test.BaseDateSearchDaoTests; import ca.uhn.fhir.storage.test.DaoTestDataBuilder; @@ -46,7 +47,6 @@ import ca.uhn.fhir.test.utilities.LogbackLevelOverrideExtension; import ca.uhn.fhir.test.utilities.docker.RequiresDocker; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; -import com.google.common.collect.Lists; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -69,6 +69,7 @@ import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.ValueSet; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -106,7 +107,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -1569,6 +1570,28 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { } + @Disabled // keeping to check search scrolling + @Test + public void withoutCount() { + createObservations(600); + + SearchParameterMap map = new SearchParameterMap(); + map.add("code", new TokenParam().setSystem("http://example.com")); + List bp = myObservationDao.searchForIds(map, new ServletRequestDetails()); + assertNotNull(bp); + assertEquals(600, bp.size()); + + } + + + private void createObservations(int theCount) { + for (int i = 0; i < theCount; i++) { + myTestDataBuilder.createObservation(asArray( + myTestDataBuilder.withObservationCode("http://example.com", "code-" + i))); + } + } + + private Consumer[] asArray(Consumer theIBaseResourceConsumer) { @SuppressWarnings("unchecked") Consumer[] array = (Consumer[]) new Consumer[]{theIBaseResourceConsumer};