From 708a42c5607ced4714b54565020137e5ed4b3c59 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 26 Sep 2022 20:41:48 -0700 Subject: [PATCH] Optimize to avoid single selects on OnToMany in mindmap. --- .../java/com/wisemapping/model/Collaboration.java | 3 +++ .../src/main/java/com/wisemapping/model/Mindmap.java | 4 ++++ .../com/wisemapping/rest/model/RestMindmapInfo.java | 11 ++--------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java index a5bc1e44..0ab3ce73 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java @@ -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; diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java b/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java index 9bd4e732..22bf1d6f 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Mindmap.java @@ -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 collaborations = new HashSet<>(); @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE}) + @Fetch(FetchMode.JOIN) @JoinTable( name = "R_LABEL_MINDMAP", joinColumns = @JoinColumn(name = "mindmap_id"), diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java index dcf680a2..1c99d05b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java @@ -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 = mindmap.findCollaboration(user); - result = collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE); - } - return result; + final Optional collaboration = mindmap.findCollaboration(user); + return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE); } public void setRole(String value) {