Skip to content

Commit

Permalink
Merge branch 'hotfix-1.10.x' into hotfix-2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
plyhun committed Jan 17, 2024
2 parents 8ce5d7c + 651e5f8 commit f93faab
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 4 deletions.
7 changes: 6 additions & 1 deletion LTS-CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ include::content/docs/variables.adoc-include[]
The LTS changelog lists releases which are only accessible via a commercial subscription.
All fixes and changes in LTS releases will be released the next minor release. Changes from LTS 1.4.x will be included in release 1.5.0.

[[v1.10.25]]
== 1.10.25 (17.01.2024)

icon:check[] GraphQL: Fetching of micronode fields has been improved to allow batch loading.

[[v1.10.24]]
== 1.10.24 (10.01.2024)

icon:check[] REST: The documentation of the generic parameter `fields` has been fixed. Now `fields` works over the Language entities as well, the values are `uuid`,`name`,`languageTag`,`nativeName`.

icon:check[] GraphQL. Some of (micro)schema fields related queries rely on the target (micro)schema having at least one field, crashing in HTTP 500 otherwise. This has now been fixed.
icon:check[] GraphQL: Some of (micro)schema fields related queries rely on the target (micro)schema having at least one field, crashing in HTTP 500 otherwise. This has now been fixed.

[[v1.10.23]]
== 1.10.23 (20.12.2023)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GraphQL: Fetching of micronode fields has been improved to allow batch loading.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.gentics.mesh.core.data.HibNodeFieldContainerEdge;
import com.gentics.mesh.core.data.branch.HibBranch;
import com.gentics.mesh.core.data.diff.FieldContainerChange;
import com.gentics.mesh.core.data.node.HibMicronode;
import com.gentics.mesh.core.data.node.HibNode;
import com.gentics.mesh.core.data.node.field.list.HibMicronodeFieldList;
import com.gentics.mesh.core.data.node.field.nesting.HibMicronodeField;
Expand Down Expand Up @@ -1143,4 +1144,18 @@ default Result<? extends HibNodeFieldContainerEdge> getFieldEdges(HibNode fieldN
* @return map of list UUIDs to lists of string field values
*/
Map<String, List<String>> getStringListFieldValues(List<String> listUuids);

/**
* Get the Micronode list field values for the given list UUIDs
* @param listUuids list UUIDs
* @return map of list UUIDs to lists of micronode field values
*/
Map<String, List<HibMicronode>> getMicronodeListFieldValues(List<String> listUuids);

/**
* Load the micronodes for the given collection of micronode fields
* @param micronodeFields micronode fields
* @return map of field to micronode
*/
Map<HibMicronodeField, HibMicronode> getMicronodes(Collection<HibMicronodeField> micronodeFields);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
* Rest model type
*/
public interface DaoTransformable<T, R extends RestModel> {
/**
* Invoked before transforming the elements in the page to their REST models
* @param page page of elements
* @param ac action context
*/
default void beforeTransformToRestSync(Page<? extends HibCoreElement<? extends RestModel>> page, InternalActionContext ac) {}

/**
* Transform the element into the matching rest model response asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public PageTransformer(Map<ElementType, DaoTransformable<HibCoreElement<? extend
* @return
*/
public ListResponse<RestModel> transformToRestSync(Page<? extends HibCoreElement<? extends RestModel>> page, InternalActionContext ac, int level) {
if (page.getSize() > 0) {
HibCoreElement<? extends RestModel> element = page.getWrappedList().get(0);
ElementType type = element.getTypeInfo().getType();
DaoTransformable<HibCoreElement<? extends RestModel>, RestModel> dao = daos.get(type);
dao.beforeTransformToRestSync(page, ac);
}

List<RestModel> responses = transformToRestSync(page.stream(), ac, level).collect(Collectors.toList());
ListResponse<RestModel> listResponse = new ListResponse<>();
page.setPaging(listResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import static com.gentics.mesh.core.data.relationship.GraphRelationships.HAS_FIELD_CONTAINER;
import static com.gentics.mesh.core.data.util.HibClassConverter.toGraph;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;


import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -391,4 +392,14 @@ public Map<String, List<String>> getHtmlListFieldValues(List<String> listUuids)
public Map<String, List<String>> getStringListFieldValues(List<String> listUuids) {
throw new NotImplementedException("Prefetching of list values is not implemented");
}

@Override
public Map<String, List<HibMicronode>> getMicronodeListFieldValues(List<String> listUuids) {
throw new NotImplementedException("Prefetching of list values is not implemented");
}

@Override
public Map<HibMicronodeField, HibMicronode> getMicronodes(Collection<HibMicronodeField> micronodeFields) {
return micronodeFields.stream().distinct().collect(Collectors.toMap(Function.identity(), HibMicronodeField::getMicronode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public void handleQuery(GraphQLContext gc, String body) {
dataLoaderRegistry.register(FieldDefinitionProvider.NUMBER_LIST_VALUES_DATA_LOADER_KEY, DataLoader.newDataLoader(typeProvider.getFieldDefProvider().NUMBER_LIST_VALUE_LOADER, dlOptions));
dataLoaderRegistry.register(FieldDefinitionProvider.HTML_LIST_VALUES_DATA_LOADER_KEY, DataLoader.newDataLoader(typeProvider.getFieldDefProvider().HTML_LIST_VALUE_LOADER, dlOptions));
dataLoaderRegistry.register(FieldDefinitionProvider.STRING_LIST_VALUES_DATA_LOADER_KEY, DataLoader.newDataLoader(typeProvider.getFieldDefProvider().STRING_LIST_VALUE_LOADER, dlOptions));
dataLoaderRegistry.register(FieldDefinitionProvider.MICRONODE_LIST_VALUES_DATA_LOADER_KEY, DataLoader.newDataLoader(typeProvider.getFieldDefProvider().MICRONODE_LIST_VALUE_LOADER, dlOptions));
dataLoaderRegistry.register(FieldDefinitionProvider.MICRONODE_DATA_LOADER_KEY, DataLoader.newDataLoader(typeProvider.getFieldDefProvider().MICRONODE_LOADER, dlOptions));

ExecutionInput executionInput = ExecutionInput
.newExecutionInput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public class FieldDefinitionProvider extends AbstractTypeProvider {
*/
public static final String STRING_LIST_VALUES_DATA_LOADER_KEY = "stringListLoader";

/**
* Key for the data loader for micronode list field values
*/
public static final String MICRONODE_LIST_VALUES_DATA_LOADER_KEY = "micronodeUuidListLoader";

/**
* Key for the data loader for micronode field values
*/
public static final String MICRONODE_DATA_LOADER_KEY = "micronodeLoader";

protected final MicronodeFieldTypeProvider micronodeFieldTypeProvider;

protected final WebRootLinkReplacerImpl linkReplacer;
Expand Down Expand Up @@ -211,6 +221,28 @@ private static <U, V> CompletionStage<List<List<V>>> listValueDataLoader(List<St
return listValueDataLoader(keys, contentDao::getStringListFieldValues, Functions.identity());
};

/**
* DataLoader implementation for values of micronode lists
*/
public BatchLoaderWithContext<String, List<HibMicronode>> MICRONODE_LIST_VALUE_LOADER = (keys, environment) -> {
ContentDao contentDao = Tx.get().contentDao();
return listValueDataLoader(keys, contentDao::getMicronodeListFieldValues, Functions.identity());
};

/**
* DataLoader implementation for micronodes
*/
public BatchLoaderWithContext<HibMicronodeField, HibMicronode> MICRONODE_LOADER = (keys, environment) -> {
ContentDao contentDao = Tx.get().contentDao();
Map<HibMicronodeField, HibMicronode> micronodes = contentDao.getMicronodes(keys);

Promise<List<HibMicronode>> promise = Promise.promise();
List<HibMicronode> result = keys.stream().map(field -> micronodes.get(field)).collect(Collectors.toList());
promise.complete(result);

return promise.future().toCompletionStage();
};

@Inject
public FieldDefinitionProvider(MeshOptions options, MicronodeFieldTypeProvider micronodeFieldTypeProvider, WebRootLinkReplacerImpl linkReplacer) {
super(options);
Expand Down Expand Up @@ -666,7 +698,14 @@ public Optional<GraphQLFieldDefinition> createListDef(GraphQLContext context, Li
if (micronodeList == null) {
return null;
}
return micronodeList.getList().stream().map(item -> item.getMicronode()).collect(Collectors.toList());

String micronodeListUuid = micronodeList.getUuid();
if (contentDao.supportsPrefetchingListFieldValues() && !StringUtils.isEmpty(micronodeListUuid)) {
DataLoader<String, List<HibMicronode>> micronodeListValueLoader = env.getDataLoader(FieldDefinitionProvider.MICRONODE_LIST_VALUES_DATA_LOADER_KEY);
return micronodeListValueLoader.load(micronodeListUuid);
} else {
return micronodeList.getList().stream().map(item -> item.getMicronode()).collect(Collectors.toList());
}
default:
return null;
}
Expand Down Expand Up @@ -713,7 +752,9 @@ public Optional<GraphQLFieldDefinition> createMicronodeDef(GraphQLContext contex
HibFieldContainer container = env.getSource();
HibMicronodeField micronodeField = container.getMicronode(schema.getName());
if (micronodeField != null) {
return micronodeField.getMicronode();

DataLoader<HibMicronodeField, HibMicronode> micronodeLoader = env.getDataLoader(MICRONODE_DATA_LOADER_KEY);
return micronodeLoader.load(micronodeField);
}
return null;
}).build());
Expand Down

0 comments on commit f93faab

Please sign in to comment.