docs: @Override
  	public HashSet<Long> loadIncludes(FhirContext theContext, EntityManager theEntityManager, Collection<Long> theMatches, Set<Include> theRevIncludes,
  												 boolean theReverseMode, DateRangeParam theLastUpdated, String theSearchIdOrDescription) {
  		if (theMatches.size() == 0) {
  			return new HashSet<>();
  		}
  		if (theRevIncludes == null || theRevIncludes.isEmpty()) {
  			return new HashSet<>();
  		}
  		String searchFieldName = theReverseMode ? "myTargetResourcePid" : "mySourceResourcePid";
  
  		Collection<Long> nextRoundMatches = theMatches;
  		HashSet<Long> allAdded = new HashSet<>();
  		HashSet<Long> original = new HashSet<>(theMatches);
  		ArrayList<Include> includes = new ArrayList<>(theRevIncludes);
  
  		int roundCounts = 0;
  		StopWatch w = new StopWatch();
  
  		boolean addedSomeThisRound;
  		do {
  			roundCounts++;
  
  			HashSet<Long> pidsToInclude = new HashSet<>();
  
  			for (Iterator<Include> iter = includes.iterator(); iter.hasNext(); ) {
  				Include nextInclude = iter.next();
  				if (nextInclude.isRecurse() == false) {
  					iter.remove();
  				}
  
  				boolean matchAll = "*".equals(nextInclude.getValue());
  				if (matchAll) {
  					String sql;
  					sql = "SELECT r FROM ResourceLink r WHERE r." + searchFieldName + " IN (:target_pids) ";
  					List<Collection<Long>> partitions = partition(nextRoundMatches, MAXIMUM_PAGE_SIZE);
  					for (Collection<Long> nextPartition : partitions) {
  						TypedQuery<ResourceLink> q = theEntityManager.createQuery(sql, ResourceLink.class);
  						q.setParameter("target_pids", nextPartition);
  						List<ResourceLink> results = q.getResultList();
  						for (ResourceLink resourceLink : results) {
  							if (theReverseMode) {
  								pidsToInclude.add(resourceLink.getSourceResourcePid());
  							} else {
  								pidsToInclude.add(resourceLink.getTargetResourcePid());
  							}
  						}
  					}
  				} else {
  
  					List<String> paths;
  					RuntimeSearchParam param;
  					String resType = nextInclude.getParamType();
  					if (isBlank(resType)) {
  						continue;
  					}
  					RuntimeResourceDefinition def = theContext.getResourceDefinition(resType);
  					if (def == null) {
  						ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue());
  						continue;
  					}
  
  					String paramName = nextInclude.getParamName();
  					if (isNotBlank(paramName)) {
  						param = mySearchParamRegistry.getSearchParamByName(def, paramName);
  					} else {
  						param = null;
  					}
  					if (param == null) {
  						ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue());
  						continue;
  					}
  
  					paths = param.getPathsSplit();
  
  					String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
  					for (String nextPath : paths) {
  						String sql;
  
  						boolean haveTargetTypesDefinedByParam = param.getTargets() != null && param.getTargets().isEmpty() == false;
  						if (targetResourceType != null) {
  							sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type";
  						} else if (haveTargetTypesDefinedByParam) {
  							sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType in (:target_resource_types)";
  						} else {
  							sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
  						}
  
  						List<Collection<Long>> partitions = partition(nextRoundMatches, MAXIMUM_PAGE_SIZE);
  						for (Collection<Long> nextPartition : partitions) {
  							TypedQuery<ResourceLink> q = theEntityManager.createQuery(sql, ResourceLink.class);
  							q.setParameter("src_path", nextPath);
  							q.setParameter("target_pids", nextPartition);
  							if (targetResourceType != null) {
  								q.setParameter("target_resource_type", targetResourceType);
  							} else if (haveTargetTypesDefinedByParam) {
  								q.setParameter("target_resource_types", param.getTargets());
  							}
  							List<ResourceLink> results = q.getResultList();
  							for (ResourceLink resourceLink : results) {
  								if (theReverseMode) {
  									Long pid = resourceLink.getSourceResourcePid();
  									if (pid != null) {
  										pidsToInclude.add(pid);
  									}
  								} else {
  									Long pid = resourceLink.getTargetResourcePid();
  									if (pid != null) {
  										pidsToInclude.add(pid);
  									}
  								}
  							}
  						}
  					}
  				}
  			}
  
  			if (theReverseMode) {
  				if (theLastUpdated != null && (theLastUpdated.getLowerBoundAsInstant() != null || theLastUpdated.getUpperBoundAsInstant() != null)) {
  					pidsToInclude = new HashSet<>(filterResourceIdsByLastUpdated(theEntityManager, theLastUpdated, pidsToInclude));
  				}
  			}
  			for (Long next : pidsToInclude) {
  				if (original.contains(next) == false && allAdded.contains(next) == false) {
  					theMatches.add(next);
  				}
  			}
  
  			addedSomeThisRound = allAdded.addAll(pidsToInclude);
  			nextRoundMatches = pidsToInclude;
  		} while (includes.size() > 0 && nextRoundMatches.size() > 0 && addedSomeThisRound);
  
  		ourLog.info("Loaded {} {} in {} rounds and {} ms for search {}", allAdded.size(), theReverseMode ? "_revincludes" : "_includes", roundCounts, w.getMillisAndRestart(), theSearchIdOrDescription);
  
  		return allAdded;
  	}