Performance optimization to avoid loading Collaboration table per map.
parent
0c88b8a474
commit
86964febc1
|
@ -112,10 +112,18 @@ public class Collaborator implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
public boolean identityEquality(@Nullable Collaborator that) {
|
public boolean identityEquality(@Nullable Collaborator that) {
|
||||||
if (this == that) return true;
|
if (this == that) {
|
||||||
if (that == null) return false;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (that == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != that.getId()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (id != that.getId()) return false;
|
|
||||||
return email != null ? email.equals(that.getEmail()) : that.getEmail() == null;
|
return email != null ? email.equals(that.getEmail()) : that.getEmail() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class Mindmap implements Serializable {
|
||||||
@Column(name = "public")
|
@Column(name = "public")
|
||||||
private boolean isPublic;
|
private boolean isPublic;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "mindMap", orphanRemoval = true, cascade = {CascadeType.ALL})
|
@OneToMany(mappedBy = "mindMap", orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
|
||||||
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})
|
||||||
|
@ -177,15 +177,14 @@ public class Mindmap implements Serializable {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCreator(@NotNull User user) {
|
||||||
|
return this.getCreator()!=null && this.getCreator().identityEquality(user);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPublic() {
|
public boolean isPublic() {
|
||||||
return isPublic;
|
return isPublic;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Todo: This is a hack to overcome some problem with JS EL. For some reason, ${mindmap.public} fails as not supported.
|
|
||||||
// More research is needed...
|
|
||||||
public boolean isAccessible() {
|
|
||||||
return isPublic();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(boolean isPublic) {
|
public void setPublic(boolean isPublic) {
|
||||||
this.isPublic = isPublic;
|
this.isPublic = isPublic;
|
||||||
|
|
|
@ -46,10 +46,10 @@ public class RestMindmapInfo {
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private final Mindmap mindmap;
|
private final Mindmap mindmap;
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Set<RestLabel> restLabels;
|
private Set<RestLabel> restLabels;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private int mapId = -1;
|
private int mapId = -1;
|
||||||
|
|
||||||
private final Collaborator collaborator;
|
private final Collaborator collaborator;
|
||||||
|
|
||||||
|
@ -91,9 +91,9 @@ public class RestMindmapInfo {
|
||||||
public Set<RestLabel> getLabels() {
|
public Set<RestLabel> getLabels() {
|
||||||
// Support test deserialization...
|
// Support test deserialization...
|
||||||
Set<RestLabel> result = this.restLabels;
|
Set<RestLabel> result = this.restLabels;
|
||||||
if(result==null) {
|
if (result == null) {
|
||||||
final User me = Utils.getUser();
|
final User me = Utils.getUser();
|
||||||
result = mindmap.getLabels().
|
result = mindmap.getLabels().
|
||||||
stream()
|
stream()
|
||||||
.filter(l -> l.getCreator().equals(me))
|
.filter(l -> l.getCreator().equals(me))
|
||||||
.map(RestLabel::new)
|
.map(RestLabel::new)
|
||||||
|
@ -107,8 +107,8 @@ public class RestMindmapInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
int result = this.mapId;
|
int result = this.mapId;
|
||||||
if(mapId==-1) {
|
if (mapId == -1) {
|
||||||
result = mindmap.getId();
|
result = mindmap.getId();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -132,8 +132,17 @@ public class RestMindmapInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRole() {
|
public String getRole() {
|
||||||
final Optional<Collaboration> collaboration = mindmap.findCollaboration(Utils.getUser());
|
final User user = Utils.getUser();
|
||||||
return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRole(String value) {
|
public void setRole(String value) {
|
||||||
|
|
Loading…
Reference in New Issue