Optimize to avoid single selects on OnToMany in mindmap.
parent
86964febc1
commit
708a42c560
|
@ -19,6 +19,9 @@
|
||||||
package com.wisemapping.model;
|
package com.wisemapping.model;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
|
@ -23,6 +23,8 @@ import com.wisemapping.exceptions.InvalidMindmapException;
|
||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
import com.wisemapping.util.ZipUtils;
|
import com.wisemapping.util.ZipUtils;
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
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.NotFound;
|
||||||
import org.hibernate.annotations.NotFoundAction;
|
import org.hibernate.annotations.NotFoundAction;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -64,9 +66,11 @@ public class Mindmap implements Serializable {
|
||||||
private boolean isPublic;
|
private boolean isPublic;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "mindMap", orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "mindMap", orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
|
||||||
|
@Fetch(FetchMode.JOIN)
|
||||||
private Set<Collaboration> collaborations = new HashSet<>();
|
private Set<Collaboration> collaborations = new HashSet<>();
|
||||||
|
|
||||||
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
|
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
|
||||||
|
@Fetch(FetchMode.JOIN)
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "R_LABEL_MINDMAP",
|
name = "R_LABEL_MINDMAP",
|
||||||
joinColumns = @JoinColumn(name = "mindmap_id"),
|
joinColumns = @JoinColumn(name = "mindmap_id"),
|
||||||
|
|
|
@ -134,15 +134,8 @@ public class RestMindmapInfo {
|
||||||
public String getRole() {
|
public String getRole() {
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
String result;
|
String result;
|
||||||
if (mindmap.isCreator(user)) {
|
final Optional<Collaboration> collaboration = mindmap.findCollaboration(user);
|
||||||
// Performance hack. In case that the person is the creator, assume that the role is owner.
|
return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRole(String value) {
|
public void setRole(String value) {
|
||||||
|
|
Loading…
Reference in New Issue