Optimize to avoid single selects on OnToMany in mindmap.

This commit is contained in:
Paulo Gustavo Veiga 2022-09-26 20:41:48 -07:00
parent 86964febc1
commit 708a42c560
3 changed files with 9 additions and 9 deletions

View File

@ -19,6 +19,9 @@
package com.wisemapping.model;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

View File

@ -23,6 +23,8 @@ import com.wisemapping.exceptions.InvalidMindmapException;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.util.ZipUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.jetbrains.annotations.NotNull;
@ -64,9 +66,11 @@ public class Mindmap implements Serializable {
private boolean isPublic;
@OneToMany(mappedBy = "mindMap", orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@Fetch(FetchMode.JOIN)
private Set<Collaboration> collaborations = new HashSet<>();
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
@Fetch(FetchMode.JOIN)
@JoinTable(
name = "R_LABEL_MINDMAP",
joinColumns = @JoinColumn(name = "mindmap_id"),

View File

@ -134,15 +134,8 @@ public class RestMindmapInfo {
public String getRole() {
final User user = Utils.getUser();
String result;
if (mindmap.isCreator(user)) {
// Performance hack. In case that the person is the creator, assume that the role is owner.
// This is to avoid loading all the collaboration maps per map.
result = CollaborationRole.OWNER.getLabel();
} else {
final Optional<Collaboration> collaboration = mindmap.findCollaboration(user);
result = collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
}
return result;
final Optional<Collaboration> collaboration = mindmap.findCollaboration(user);
return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
}
public void setRole(String value) {