From abc894ce90c46425ce0fcafe8cc01ab1d71fda19 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 23 Aug 2019 10:57:58 -0400 Subject: [PATCH] A few refactors based on ken's suggestions --- .../jpa/search/SearchCoordinatorSvcImpl.java | 2 +- .../DatabaseSearchResultCacheSvcImpl.java | 2 +- .../search/cache/ISearchResultCacheSvc.java | 39 ++++++++++--------- .../jpa/term/BaseHapiTerminologySvcImpl.java | 1 + 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java index 0f5c2c34eaa..a22d854bd89 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java @@ -357,7 +357,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc { } // Check for a search matching the given hash - Collection candidates = mySearchResultCacheSvc.findCandidatesForReuse(resourceType, queryString, createdCutoff); + Collection candidates = mySearchResultCacheSvc.findCandidatesForReuse(resourceType, queryString, queryString.hashCode(), createdCutoff); for (Search nextCandidateSearch : candidates) { if (queryString.equals(nextCandidateSearch.getSearchQueryString()) && nextCandidateSearch.getCreated().after(createdCutoff)) { searchToUse = nextCandidateSearch; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java index c72a8f9ea44..ec2c672c1fb 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java @@ -137,7 +137,7 @@ public class DatabaseSearchResultCacheSvcImpl extends BaseSearchResultCacheSvcIm } @Override - public Collection findCandidatesForReuse(String theResourceType, String theQueryString, Date theCreatedAfter) { + public Collection findCandidatesForReuse(String theResourceType, String theQueryString, int theQueryStringHash, Date theCreatedAfter) { int hashCode = theQueryString.hashCode(); return mySearchDao.find(theResourceType, hashCode, theCreatedAfter); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java index 0cfc23bb36e..77b9805960d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java @@ -27,26 +27,9 @@ public interface ISearchResultCacheSvc { */ Optional fetchByUuid(String theUuid); - /** - * Fetch a sunset of the search result IDs from the cache - * - * @param theSearch The search to fetch IDs for - * @param theFrom The starting index (inclusive) - * @param theTo The ending index (exclusive) - * @return A list of resource PIDs - */ - List fetchResultPids(Search theSearch, int theFrom, int theTo); - - /** - * Fetch all result PIDs for a given search with no particular order required - * @param theSearch - * @return - */ - List fetchAllResultPids(Search theSearch); - /** * TODO: this is perhaps an inappropriate responsibility for this service - * + * *

* This method marks a search as in progress, but should only allow exactly one call to do so across the cluster. This * is done so that if two client threads request the next page at the exact same time (which is unlikely but not @@ -70,10 +53,11 @@ public interface ISearchResultCacheSvc { * * @param theResourceType The resource type of the search. Results MUST match this type * @param theQueryString The query string. Results SHOULD match this type + * @param theQueryStringHash The query string hash. Results SHOULD match this type * @param theCreatedAfter Results SHOULD not include any searches created before this cutoff timestamp * @return A collection of candidate searches */ - Collection findCandidatesForReuse(String theResourceType, String theQueryString, Date theCreatedAfter); + Collection findCandidatesForReuse(String theResourceType, String theQueryString, int theQueryStringHash, Date theCreatedAfter); /** * Mark a search as having been "last used" at the given time. This method may (and probably should) be implemented @@ -102,4 +86,21 @@ public interface ISearchResultCacheSvc { * @param theNewResourcePids A list of new resoure PIDs to add to this search (these ones have not been previously saved) */ void storeResults(Search theSearch, List thePreviouslyStoredResourcePids, List theNewResourcePids); + + /** + * Fetch a sunset of the search result IDs from the cache + * + * @param theSearch The search to fetch IDs for + * @param theFrom The starting index (inclusive) + * @param theTo The ending index (exclusive) + * @return A list of resource PIDs + */ + List fetchResultPids(Search theSearch, int theFrom, int theTo); + + /** + * Fetch all result PIDs for a given search with no particular order required + * @param theSearch + * @return + */ + List fetchAllResultPids(Search theSearch); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java index c574f84a122..53298913b0b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvcImpl.java @@ -648,6 +648,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc, FullTextQuery jpaQuery = em.createFullTextQuery(luceneQuery, TermConcept.class); int maxResult = 50000; jpaQuery.setMaxResults(maxResult); + jpaQuery.setFirstResult() StopWatch sw = new StopWatch(); AtomicInteger count = new AtomicInteger(0);