Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1008: Fixed sql looping issue #1010

Merged
merged 2 commits into from Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -87,6 +87,7 @@
import ca.uhn.fhir.jpa.dao.data.IResourceTagDao;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamNumber;
Expand Down Expand Up @@ -1688,8 +1689,19 @@ private void doLoadPids(List<IBaseResource> theResourceListToPopulate, Set<Long>
//-- preload all tags with tag definition if any
Map<Long, Collection<ResourceTag>> tagMap = getResourceTagMap(resultList);

//-- pre-load all forcedId
Map<Long, ForcedId> forcedIdMap = getForcedIdMap(pids);

ForcedId forcedId = null;
Long resourceId = null;
for (ResourceTable next : resultList) {
Class<? extends IBaseResource> resourceType = context.getResourceDefinition(next.getResourceType()).getImplementingClass();

resourceId = next.getId();
forcedId = forcedIdMap.get(resourceId);
if (forcedId != null)
next.setForcedId(forcedId);

IBaseResource resource = theDao.toResource(resourceType, next, historyMap.get(next.getId()), tagMap.get(next.getId()), theForHistoryOperation);
if (resource == null) {
ourLog.warn("Unable to find resource {}/{}/_history/{} in database", next.getResourceType(), next.getIdDt().getIdPart(), next.getVersion());
Expand Down Expand Up @@ -1775,6 +1787,23 @@ private Map<Long, Collection<ResourceTag>> getResourceTagMap(List<ResourceTable>
return tagMap;
}

//-- load all forcedId in to the map
private Map<Long, ForcedId> getForcedIdMap(Collection<Long> pids) {

Map<Long, ForcedId> forceIdMap = new HashMap<Long, ForcedId>();

if (pids.size() == 0)
return forceIdMap;

Collection<ForcedId> forceIdList = myForcedIdDao.findByResourcePids(pids);

for (ForcedId forcedId : forceIdList) {

forceIdMap.put(forcedId.getResourcePid(), forcedId);
}

return forceIdMap;
}
@Override
public void loadResourcesByPid(Collection<Long> theIncludePids, List<IBaseResource> theResourceListToPopulate, Set<Long> theRevIncludedPids, boolean theForHistoryOperation,
EntityManager entityManager, FhirContext context, IDao theDao) {
Expand Down
@@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.dao.data;

import java.util.Collection;
import java.util.List;

/*
Expand Down Expand Up @@ -38,5 +39,7 @@ public interface IForcedIdDao extends JpaRepository<ForcedId, Long> {

@Query("SELECT f FROM ForcedId f WHERE f.myResourcePid = :resource_pid")
public ForcedId findByResourcePid(@Param("resource_pid") Long theResourcePid);


@Query("SELECT f FROM ForcedId f WHERE f.myResourcePid in (:pids)")
Collection<ForcedId> findByResourcePids(@Param("pids") Collection<Long> pids);
}
Expand Up @@ -42,7 +42,7 @@ public abstract class BaseHasResource {
@OptimisticLock(excluded = true)
private FhirVersionEnum myFhirVersion;

@OneToOne(optional = true, fetch = FetchType.EAGER, cascade = {}, orphanRemoval = false)
@OneToOne(optional = true, fetch = FetchType.LAZY, cascade = {}, orphanRemoval = false)
@JoinColumn(name = "FORCED_ID_PID")
@OptimisticLock(excluded = true)
private ForcedId myForcedId;
Expand Down