Small perf improvement for JPA terminology

This commit is contained in:
James Agnew 2017-08-24 13:06:47 -04:00
parent 72245c00d0
commit 1ec14f4a31
6 changed files with 48 additions and 46 deletions

View File

@ -35,7 +35,7 @@ public interface ITermConceptParentChildLinkDao extends JpaRepository<TermConcep
@Modifying @Modifying
void deleteByCodeSystemVersion(@Param("cs_pid") Long thePid); void deleteByCodeSystemVersion(@Param("cs_pid") Long thePid);
@Query("SELECT t FROM TermConceptParentChildLink t WHERE t.myChildPid = :child_pid") @Query("SELECT t.myParentPid FROM TermConceptParentChildLink t WHERE t.myChildPid = :child_pid")
Collection<TermConceptParentChildLink> findAllWithChild(@Param("child_pid") Long theConceptPid); Collection<Long> findAllWithChild(@Param("child_pid") Long theConceptPid);
} }

View File

@ -357,13 +357,14 @@ public abstract class BaseHapiTerminologySvc implements IHapiTerminologySvc {
if (parents.contains(-1L)) { if (parents.contains(-1L)) {
return; return;
} else if (parents.isEmpty()) { } else if (parents.isEmpty()) {
Collection<TermConceptParentChildLink> parentLinks = myConceptParentChildLinkDao.findAllWithChild(theConceptPid); ourLog.info("Loading parent concepts of concept {}", theConceptPid);
Collection<Long> parentLinks = myConceptParentChildLinkDao.findAllWithChild(theConceptPid);
if (parentLinks.isEmpty()) { if (parentLinks.isEmpty()) {
myChildToParentPidCache.put(theConceptPid, -1L); myChildToParentPidCache.put(theConceptPid, -1L);
return; return;
} else { } else {
for (TermConceptParentChildLink next : parentLinks) { for (Long next : parentLinks) {
myChildToParentPidCache.put(theConceptPid, next.getParentPid()); myChildToParentPidCache.put(theConceptPid, next);
} }
} }
} }
@ -382,6 +383,7 @@ public abstract class BaseHapiTerminologySvc implements IHapiTerminologySvc {
int maxResult = 1000; int maxResult = 1000;
Page<TermConcept> concepts = myConceptDao.findResourcesRequiringReindexing(new PageRequest(0, maxResult)); Page<TermConcept> concepts = myConceptDao.findResourcesRequiringReindexing(new PageRequest(0, maxResult));
if (concepts.hasContent() == false) { if (concepts.hasContent() == false) {
ourLog.info("Clearing parent concept cache");
myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE;
myChildToParentPidCache = null; myChildToParentPidCache = null;
return; return;

View File

@ -11,6 +11,7 @@ curl -H "Authorization: Bearer " "http://fhirtest.uhn.ca/baseDstu3/\$mark-all-re
# Delete all errored resources # Delete all errored resources
update hfj_res_ver set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2); update hfj_res_ver set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2);
update hfj_resource set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2); update hfj_resource set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_history_tag where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_ver where res_id in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_res_ver where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_forced_id where resource_pid in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_forced_id where resource_pid in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_link where src_resource_id in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_res_link where src_resource_id in (select res_id from hfj_resource where sp_index_status = 2);

View File

@ -351,6 +351,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter {
* *
* @return Returns a reference to this for easy method chaining * @return Returns a reference to this for easy method chaining
*/ */
@SuppressWarnings("UnusedReturnValue")
public ResponseHighlighterInterceptor setShowRequestHeaders(boolean theShowRequestHeaders) { public ResponseHighlighterInterceptor setShowRequestHeaders(boolean theShowRequestHeaders) {
myShowRequestHeaders = theShowRequestHeaders; myShowRequestHeaders = theShowRequestHeaders;
return this; return this;
@ -362,6 +363,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter {
* *
* @return Returns a reference to this for easy method chaining * @return Returns a reference to this for easy method chaining
*/ */
@SuppressWarnings("UnusedReturnValue")
public ResponseHighlighterInterceptor setShowResponseHeaders(boolean theShowResponseHeaders) { public ResponseHighlighterInterceptor setShowResponseHeaders(boolean theShowResponseHeaders) {
myShowResponseHeaders = theShowResponseHeaders; myShowResponseHeaders = theShowResponseHeaders;
return this; return this;
@ -415,7 +417,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter {
} }
} }
if (prettyPrintResponse) { if (prettyPrintResponse) {
p.setPrettyPrint(prettyPrintResponse); p.setPrettyPrint(true);
} }
EncodingEnum encoding = p.getEncoding(); EncodingEnum encoding = p.getEncoding();
@ -558,18 +560,16 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter {
b.append("\n"); b.append("\n");
b.append("\n"); b.append("\n");
if (true) { try {
try { if (isShowRequestHeaders()) {
if (isShowRequestHeaders()) { streamRequestHeaders(theServletRequest, b);
streamRequestHeaders(theServletRequest, b); }
} if (isShowResponseHeaders()) {
if (isShowResponseHeaders()) { streamResponseHeaders(theRequestDetails, theServletResponse, b);
streamResponseHeaders(theRequestDetails, theServletResponse, b); }
} } catch (Throwable t) {
} catch (Throwable t) { // ignore (this will hit if we're running in a servlet 2.5 environment)
// ignore (this will hit if we're running in a servlet 2.5 environment) }
}
}
StringBuilder target = new StringBuilder(); StringBuilder target = new StringBuilder();
int linesCount = format(encoded, target, encoding); int linesCount = format(encoded, target, encoding);

View File

@ -761,6 +761,7 @@ public class ResponseHighlightingInterceptorTest {
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort(); ourPort = PortUtil.findFreePort();
ourLog.info("Using port: {}", ourPort);
ourServer = new Server(ourPort); ourServer = new Server(ourPort);
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();

View File

@ -1,33 +1,5 @@
package ca.uhn.fhir.rest.server.interceptor; package ca.uhn.fhir.rest.server.interceptor;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.*;
import org.mockito.ArgumentCaptor;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.context.api.BundleInclusionRule;
import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.dstu2.resource.Observation;
@ -44,6 +16,32 @@ import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
public class ServerActionInterceptorTest { public class ServerActionInterceptorTest {