@Override
public List<Site> findSites(SiteQuery query) {
Parameters.requireNonNull(query, "query");
Pagination pagination = query.getPagination();
if (pagination != null && query.getSiteTypes().size() > 1) {
pagination = null; // set it to null so the internal DataStorage doesn't use it, and we manually page later
log.warn("Pagination is not supported internally for SiteQuery's with multiple site types. Therefore this query has the possibility to perform poorly.");
}
boolean includeAll = query.isIncludeEmptySites();
List<Site> sites = new ArrayList<Site>();
for (SiteType type : query.getSiteTypes()) {
List<Site> sitesFound;
switch (type) {
case SITE:
sitesFound = findSites(pagination, SITES, Comparators.site(query.getSorting()), includeAll);
break;
case SPACE:
sitesFound = findSites(pagination, SPACES, Comparators.site(query.getSorting()), includeAll);
break;
case DASHBOARD:
sitesFound = findSites(pagination, DASHBOARDS, Comparators.site(query.getSorting()), includeAll);
break;
default:
throw new AssertionError();
}
sites.addAll(sitesFound);
// No reason to fetch anymore
if (pagination != null && sites.size() >= pagination.getLimit()) {
break;
}
}
filter(sites, query.getFilter());