We have a page that queries entities with certain criteria.
The way we implement it is by getting list of entity IDs, loop the IDs retrieve the entity model per ID and add it into the list.
Pseudo code:
Query query = new Query(...);
// Get list of ids from query
List<String> ids = Arrays.asList(query.executeQuery());
final WebComponentMetaFactory cmf = new WebComponentMetaFactoryImpl(brokerQuery.getPublicationId());
// Get component meta
List<ComponentMeta> componentMetas = ids.stream().map(cmf::getMeta)
.collect(Collectors.toList());
// Get entity model per component and add it to the list
componentMetas.forEach(meta -> {
EntityModel entityModel = contentProvider.getEntityModel(meta.getId() + templateId, webRequestContext.getLocalization())
list.add(entityModel)
});
This works, however from performance point of view is very slow because it needs to call contentProvider.getEntityModel(...)
for every ID.
Is there a better solution for this? Perhaps an API from DXA that generates list of EntityModel?