Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Core: The performance of updating (micro)schemas has been improved.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PluginRouterImpl implements PluginRouter {

public static final String PLUGINS_MOUNTPOINT = "/plugins";

private static final Logger log = LoggerFactory.getLogger(APIRouterImpl.class);
private static final Logger log = LoggerFactory.getLogger(PluginRouterImpl.class);

private Map<String, Router> pluginRouters = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gentics.mesh.hibernate.data.domain;

import javax.annotation.Nonnull;

import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;

Expand All @@ -17,7 +19,7 @@
@MappedSuperclass
public abstract class AbstractHibBranchSchemaVersion<SCV extends AbstractHibFieldSchemaVersion<?, ?, ?, ?, ?>> extends AbstractHibBaseElement {

@ManyToOne(optional = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rarely need the version's branch info, unlike the schema below.

private HibBranchImpl branch;

@ManyToOne(optional = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gentics.mesh.hibernate.data.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -39,6 +40,7 @@
import com.gentics.mesh.core.result.TraversalResult;
import com.gentics.mesh.dagger.annotations.ElementTypeKey;
import com.gentics.mesh.database.HibernateTx;
import com.gentics.mesh.hibernate.util.TriFunction;
import com.gentics.mesh.parameter.PagingParameters;

import jakarta.persistence.CascadeType;
Expand Down Expand Up @@ -86,10 +88,10 @@ public class HibBranchImpl extends AbstractHibUserTrackedElement<BranchResponse>
private HibBranch previousBranch;

@OneToMany(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<HibBranchSchemaVersionEdgeImpl> schemaVersions = new HashSet<>();
private List<HibBranchSchemaVersionEdgeImpl> schemaVersions = new ArrayList<>();

@OneToMany(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<HibBranchMicroschemaVersionEdgeImpl> microschemaVersions = new HashSet<>();
private List<HibBranchMicroschemaVersionEdgeImpl> microschemaVersions = new ArrayList<>();

@ManyToMany(targetEntity = HibTagImpl.class, fetch = FetchType.LAZY)
private Set<HibTag> tags = new HashSet<>();
Expand Down Expand Up @@ -164,26 +166,42 @@ public HibBranch setPathPrefix(String pathPrefix) {
return this;
}

/**
* Add/ensure existing the schema version to this branch.
*
* @param version
* @return
*/
public HibBranchSchemaVersionEdgeImpl addSchemaVersion(HibSchemaVersionImpl version) {
HibernateTx tx = HibernateTx.get();
HibBranchSchemaVersionEdgeImpl sve = new HibBranchSchemaVersionEdgeImpl(tx, this, version);
tx.entityManager().persist(sve);
schemaVersions.add(sve);
return sve;
return addVersion(version, HibBranchSchemaVersionEdgeImpl.class, schemaVersions, HibBranchSchemaVersionEdgeImpl::new);
}

/**
* Add/ensure existing the microschema version to this branch.
*
* @param version
* @return
*/
public HibBranchMicroschemaVersionEdgeImpl addMicroschemaVersion(HibMicroschemaVersionImpl version) {
HibernateTx tx = HibernateTx.get();
HibBranchMicroschemaVersionEdgeImpl mve = new HibBranchMicroschemaVersionEdgeImpl(tx, this, version);
tx.entityManager().persist(mve);
microschemaVersions.add(mve);
return mve;
return addVersion(version, HibBranchMicroschemaVersionEdgeImpl.class, microschemaVersions, HibBranchMicroschemaVersionEdgeImpl::new);
}

/**
* Remove/ensure removed the schema version from this branch.
*
* @param version
* @return
*/
public boolean removeSchemaVersion(HibSchemaVersion version) {
return removeVersion(version, schemaVersions);
}

/**
* Remove/ensure removed the microschema version from this branch.
*
* @param version
* @return
*/
public boolean removeMicroschemaVersion(HibMicroschemaVersion version) {
return removeVersion(version, microschemaVersions);
}
Expand Down Expand Up @@ -362,7 +380,7 @@ public BranchReference transformToReference() {
SC extends HibFieldSchemaElement<R, RM, RE, SC, SCV>,
SCV extends HibFieldSchemaVersionElement<R, RM, RE, SC, SCV>,
I extends AbstractHibFieldSchemaVersion<R, RM, RE, SC, SCV>
> boolean removeVersion(SCV version, Set<? extends AbstractHibBranchSchemaVersion<I>> versions) {
> boolean removeVersion(SCV version, Collection<? extends AbstractHibBranchSchemaVersion<I>> versions) {
HibernateTx tx = HibernateTx.get();

// Collect versions to delete
Expand All @@ -377,4 +395,29 @@ > boolean removeVersion(SCV version, Set<? extends AbstractHibBranchSchemaVersio
});
return !toRemove.isEmpty();
}

private final <
R extends FieldSchemaContainer,
RM extends FieldSchemaContainerVersion,
RE extends NameUuidReference<RE>,
SC extends HibFieldSchemaElement<R, RM, RE, SC, SCV>,
SCV extends HibFieldSchemaVersionElement<R, RM, RE, SC, SCV>,
I extends AbstractHibFieldSchemaVersion<R, RM, RE, SC, SCV>,
E extends AbstractHibBranchSchemaVersion<I>
> E addVersion(I version, Class<E> edgeClass, Collection<E> versions, TriFunction<HibernateTx, HibBranchImpl, I, E> edgeSupplier) {
HibernateTx tx = HibernateTx.get();

return tx.entityManager()
.createQuery("select e from %s e where e.branch = :branch and e.version = :version".formatted(edgeClass.getAnnotation(Entity.class).name()), edgeClass)
.setMaxResults(1)
.setParameter("branch", this)
.setParameter("version", version)
.getResultList().stream().findAny()
.orElseGet(() -> {
E edge = edgeSupplier.apply(tx, this, version);
tx.entityManager().persist(edge);
versions.add(edge);
return edge;
});
}
}