summaryrefslogtreecommitdiff
path: root/src/main/java/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index d3e7712..1ddffa8 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -44,10 +44,12 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Where;
@Entity
@Table(name = "posts", schema = "benki")
@@ -113,6 +115,12 @@ public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
@JsonbTransient
public Collection<LazychatMessage> referrers;
+ @ManyToMany(mappedBy = "referees")
+ @OrderBy("date DESC")
+ @Where(clause = "scope = 'comment'")
+ @JsonbTransient
+ public Collection<LazychatMessage> comments;
+
@OneToMany(
mappedBy = "post",
fetch = FetchType.LAZY,
@@ -216,6 +224,9 @@ public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
cb = cb.where("post.scope").eq(Scope.top_level);
+ cb = cb.leftJoinFetch("post.comments", "comment");
+ cb = cb.fetch("comment.texts");
+
return cb;
}
@@ -393,16 +404,6 @@ public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
}
}
- public Collection<LazychatMessage> getComments() {
- return referrers.stream()
- .filter(l -> l.scope == Scope.comment)
- .sorted(
- Comparator.comparing(
- (LazychatMessage l) -> Objects.requireNonNullElse(l.date, OffsetDateTime.MIN))
- .reversed())
- .toList();
- }
-
public enum Visibility {
PUBLIC,
SEMIPRIVATE,