mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 06:50:53 +08:00
Compare commits
1 Commits
bugfix/105
...
bugfix/113
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e13ee1ca46 |
@@ -217,7 +217,11 @@ public class PostController {
|
|||||||
// userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return postMapper.toListDtos(postService.defaultListPosts(ids, tids, page, pageSize));
|
return postService
|
||||||
|
.defaultListPosts(ids, tids, page, pageSize)
|
||||||
|
.stream()
|
||||||
|
.map(postMapper::toSummaryDto)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/recent")
|
@GetMapping("/recent")
|
||||||
@@ -265,7 +269,11 @@ public class PostController {
|
|||||||
// userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return postMapper.toListDtos(postService.listPostsByViews(ids, tids, page, pageSize));
|
return postService
|
||||||
|
.listPostsByViews(ids, tids, page, pageSize)
|
||||||
|
.stream()
|
||||||
|
.map(postMapper::toSummaryDto)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/latest-reply")
|
@GetMapping("/latest-reply")
|
||||||
@@ -297,7 +305,8 @@ public class PostController {
|
|||||||
// userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return postMapper.toListDtos(postService.listPostsByLatestReply(ids, tids, page, pageSize));
|
List<Post> posts = postService.listPostsByLatestReply(ids, tids, page, pageSize);
|
||||||
|
return posts.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/featured")
|
@GetMapping("/featured")
|
||||||
@@ -324,6 +333,10 @@ public class PostController {
|
|||||||
// if (auth != null) {
|
// if (auth != null) {
|
||||||
// userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
// }
|
// }
|
||||||
return postMapper.toListDtos(postService.listFeaturedPosts(ids, tids, page, pageSize));
|
return postService
|
||||||
|
.listFeaturedPosts(ids, tids, page, pageSize)
|
||||||
|
.stream()
|
||||||
|
.map(postMapper::toSummaryDto)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,38 +48,6 @@ public class PostMapper {
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PostSummaryDto> toListDtos(List<Post> posts) {
|
|
||||||
if (posts == null || posts.isEmpty()) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
Map<Long, List<User>> participantsMap = commentService.getParticipantsForPosts(posts, 5);
|
|
||||||
return posts
|
|
||||||
.stream()
|
|
||||||
.map(post -> {
|
|
||||||
PostSummaryDto dto = new PostSummaryDto();
|
|
||||||
applyListFields(post, dto);
|
|
||||||
List<User> participants = participantsMap.get(post.getId());
|
|
||||||
if (participants != null) {
|
|
||||||
dto.setParticipants(
|
|
||||||
participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
dto.setParticipants(List.of());
|
|
||||||
}
|
|
||||||
dto.setReactions(List.of());
|
|
||||||
return dto;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostSummaryDto toListDto(Post post) {
|
|
||||||
PostSummaryDto dto = new PostSummaryDto();
|
|
||||||
applyListFields(post, dto);
|
|
||||||
dto.setParticipants(List.of());
|
|
||||||
dto.setReactions(List.of());
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostDetailDto toDetailDto(Post post, String viewer) {
|
public PostDetailDto toDetailDto(Post post, String viewer) {
|
||||||
PostDetailDto dto = new PostDetailDto();
|
PostDetailDto dto = new PostDetailDto();
|
||||||
applyCommon(post, dto);
|
applyCommon(post, dto);
|
||||||
@@ -93,25 +61,6 @@ public class PostMapper {
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyListFields(Post post, PostSummaryDto dto) {
|
|
||||||
dto.setId(post.getId());
|
|
||||||
dto.setTitle(post.getTitle());
|
|
||||||
dto.setContent(post.getContent());
|
|
||||||
dto.setCreatedAt(post.getCreatedAt());
|
|
||||||
dto.setAuthor(userMapper.toAuthorDto(post.getAuthor()));
|
|
||||||
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
|
||||||
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
|
||||||
dto.setViews(post.getViews());
|
|
||||||
dto.setCommentCount(post.getCommentCount());
|
|
||||||
dto.setStatus(post.getStatus());
|
|
||||||
dto.setPinnedAt(post.getPinnedAt());
|
|
||||||
dto.setLastReplyAt(post.getLastReplyAt());
|
|
||||||
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
|
|
||||||
dto.setClosed(post.isClosed());
|
|
||||||
dto.setVisibleScope(post.getVisibleScope());
|
|
||||||
dto.setType(post.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyCommon(Post post, PostSummaryDto dto) {
|
private void applyCommon(Post post, PostSummaryDto dto) {
|
||||||
dto.setId(post.getId());
|
dto.setId(post.getId());
|
||||||
dto.setTitle(post.getTitle());
|
dto.setTitle(post.getTitle());
|
||||||
|
|||||||
@@ -25,13 +25,6 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
|||||||
@org.springframework.data.repository.query.Param("post") Post post
|
@org.springframework.data.repository.query.Param("post") Post post
|
||||||
);
|
);
|
||||||
|
|
||||||
@org.springframework.data.jpa.repository.Query(
|
|
||||||
"SELECT DISTINCT c.post.id, c.author FROM Comment c WHERE c.post.id IN :postIds"
|
|
||||||
)
|
|
||||||
java.util.List<Object[]> findDistinctAuthorsByPostIds(
|
|
||||||
@org.springframework.data.repository.query.Param("postIds") java.util.List<Long> postIds
|
|
||||||
);
|
|
||||||
|
|
||||||
@org.springframework.data.jpa.repository.Query(
|
@org.springframework.data.jpa.repository.Query(
|
||||||
"SELECT MAX(c.createdAt) FROM Comment c WHERE c.post = :post"
|
"SELECT MAX(c.createdAt) FROM Comment c WHERE c.post = :post"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||||||
List<Post> findByStatusOrderByCreatedAtDesc(PostStatus status, Pageable pageable);
|
List<Post> findByStatusOrderByCreatedAtDesc(PostStatus status, Pageable pageable);
|
||||||
List<Post> findByStatusOrderByViewsDesc(PostStatus status);
|
List<Post> findByStatusOrderByViewsDesc(PostStatus status);
|
||||||
List<Post> findByStatusOrderByViewsDesc(PostStatus status, Pageable pageable);
|
List<Post> findByStatusOrderByViewsDesc(PostStatus status, Pageable pageable);
|
||||||
List<Post> findByStatusOrderByPinnedAtDescViewsDesc(PostStatus status, Pageable pageable);
|
|
||||||
List<Post> findByStatusOrderByPinnedAtDescLastReplyAtDesc(PostStatus status, Pageable pageable);
|
|
||||||
List<Post> findByStatusAndCreatedAtGreaterThanEqualOrderByCreatedAtDesc(
|
List<Post> findByStatusAndCreatedAtGreaterThanEqualOrderByCreatedAtDesc(
|
||||||
PostStatus status,
|
PostStatus status,
|
||||||
LocalDateTime createdAt
|
LocalDateTime createdAt
|
||||||
@@ -45,16 +43,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||||||
PostStatus status,
|
PostStatus status,
|
||||||
Pageable pageable
|
Pageable pageable
|
||||||
);
|
);
|
||||||
List<Post> findByCategoryInAndStatusOrderByPinnedAtDescViewsDesc(
|
|
||||||
List<Category> categories,
|
|
||||||
PostStatus status,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
List<Post> findByCategoryInAndStatusOrderByPinnedAtDescLastReplyAtDesc(
|
|
||||||
List<Category> categories,
|
|
||||||
PostStatus status,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
List<Post> findDistinctByTagsInAndStatus(List<Tag> tags, PostStatus status);
|
List<Post> findDistinctByTagsInAndStatus(List<Tag> tags, PostStatus status);
|
||||||
List<Post> findDistinctByTagsInAndStatus(List<Tag> tags, PostStatus status, Pageable pageable);
|
List<Post> findDistinctByTagsInAndStatus(List<Tag> tags, PostStatus status, Pageable pageable);
|
||||||
List<Post> findDistinctByTagsInAndStatusOrderByCreatedAtDesc(List<Tag> tags, PostStatus status);
|
List<Post> findDistinctByTagsInAndStatusOrderByCreatedAtDesc(List<Tag> tags, PostStatus status);
|
||||||
@@ -144,26 +132,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||||||
Pageable pageable
|
Pageable pageable
|
||||||
);
|
);
|
||||||
|
|
||||||
@Query(
|
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.pinnedAt DESC, p.views DESC"
|
|
||||||
)
|
|
||||||
List<Post> findByAllTagsOrderByPinnedAtDescViewsDesc(
|
|
||||||
@Param("tags") List<Tag> tags,
|
|
||||||
@Param("status") PostStatus status,
|
|
||||||
@Param("tagCount") long tagCount,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
|
|
||||||
@Query(
|
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.pinnedAt DESC, p.lastReplyAt DESC"
|
|
||||||
)
|
|
||||||
List<Post> findByAllTagsOrderByPinnedAtDescLastReplyAtDesc(
|
|
||||||
@Param("tags") List<Tag> tags,
|
|
||||||
@Param("status") PostStatus status,
|
|
||||||
@Param("tagCount") long tagCount,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount"
|
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount"
|
||||||
)
|
)
|
||||||
@@ -206,28 +174,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||||||
Pageable pageable
|
Pageable pageable
|
||||||
);
|
);
|
||||||
|
|
||||||
@Query(
|
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.pinnedAt DESC, p.views DESC"
|
|
||||||
)
|
|
||||||
List<Post> findByCategoriesAndAllTagsOrderByPinnedAtDescViewsDesc(
|
|
||||||
@Param("categories") List<Category> categories,
|
|
||||||
@Param("tags") List<Tag> tags,
|
|
||||||
@Param("status") PostStatus status,
|
|
||||||
@Param("tagCount") long tagCount,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
|
|
||||||
@Query(
|
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.pinnedAt DESC, p.lastReplyAt DESC"
|
|
||||||
)
|
|
||||||
List<Post> findByCategoriesAndAllTagsOrderByPinnedAtDescLastReplyAtDesc(
|
|
||||||
@Param("categories") List<Category> categories,
|
|
||||||
@Param("tags") List<Tag> tags,
|
|
||||||
@Param("status") PostStatus status,
|
|
||||||
@Param("tagCount") long tagCount,
|
|
||||||
Pageable pageable
|
|
||||||
);
|
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.createdAt DESC"
|
"SELECT p FROM Post p JOIN p.tags t WHERE p.category IN :categories AND t IN :tags AND p.status = :status GROUP BY p.id HAVING COUNT(DISTINCT t.id) = :tagCount ORDER BY p.createdAt DESC"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,12 +21,8 @@ import com.openisle.service.NotificationService;
|
|||||||
import com.openisle.service.PointService;
|
import com.openisle.service.PointService;
|
||||||
import com.openisle.service.SubscriptionService;
|
import com.openisle.service.SubscriptionService;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -320,37 +316,6 @@ public class CommentService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, List<User>> getParticipantsForPosts(List<Post> posts, int limit) {
|
|
||||||
if (posts == null || posts.isEmpty()) {
|
|
||||||
return Map.of();
|
|
||||||
}
|
|
||||||
Map<Long, LinkedHashSet<User>> map = new HashMap<>();
|
|
||||||
List<Long> postIds = new ArrayList<>(posts.size());
|
|
||||||
for (Post post : posts) {
|
|
||||||
postIds.add(post.getId());
|
|
||||||
LinkedHashSet<User> set = new LinkedHashSet<>();
|
|
||||||
set.add(post.getAuthor());
|
|
||||||
map.put(post.getId(), set);
|
|
||||||
}
|
|
||||||
for (Object[] row : commentRepository.findDistinctAuthorsByPostIds(postIds)) {
|
|
||||||
Long postId = (Long) row[0];
|
|
||||||
User author = (User) row[1];
|
|
||||||
LinkedHashSet<User> set = map.get(postId);
|
|
||||||
if (set != null) {
|
|
||||||
set.add(author);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Map<Long, List<User>> result = new HashMap<>(map.size());
|
|
||||||
for (Map.Entry<Long, LinkedHashSet<User>> entry : map.entrySet()) {
|
|
||||||
List<User> list = new ArrayList<>(entry.getValue());
|
|
||||||
if (list.size() > limit) {
|
|
||||||
list = list.subList(0, limit);
|
|
||||||
}
|
|
||||||
result.put(entry.getKey(), list);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.List<Comment> getCommentsByIds(java.util.List<Long> ids) {
|
public java.util.List<Comment> getCommentsByIds(java.util.List<Long> ids) {
|
||||||
log.debug("getCommentsByIds called for ids {}", ids);
|
log.debug("getCommentsByIds called for ids {}", ids);
|
||||||
java.util.List<Comment> comments = commentRepository.findAllById(ids);
|
java.util.List<Comment> comments = commentRepository.findAllById(ids);
|
||||||
|
|||||||
@@ -339,7 +339,6 @@ public class PostService {
|
|||||||
post.setCategory(category);
|
post.setCategory(category);
|
||||||
post.setTags(new HashSet<>(tags));
|
post.setTags(new HashSet<>(tags));
|
||||||
post.setStatus(publishMode == PublishMode.REVIEW ? PostStatus.PENDING : PostStatus.PUBLISHED);
|
post.setStatus(publishMode == PublishMode.REVIEW ? PostStatus.PENDING : PostStatus.PUBLISHED);
|
||||||
post.setLastReplyAt(LocalDateTime.now());
|
|
||||||
|
|
||||||
// 什么都没设置的情况下,默认为ALL
|
// 什么都没设置的情况下,默认为ALL
|
||||||
if (Objects.isNull(postVisibleScopeType)) {
|
if (Objects.isNull(postVisibleScopeType)) {
|
||||||
@@ -810,10 +809,9 @@ public class PostService {
|
|||||||
boolean hasTags = tagIds != null && !tagIds.isEmpty();
|
boolean hasTags = tagIds != null && !tagIds.isEmpty();
|
||||||
|
|
||||||
java.util.List<Post> posts;
|
java.util.List<Post> posts;
|
||||||
Pageable pageable = buildPageable(page, pageSize);
|
|
||||||
|
|
||||||
if (!hasCategories && !hasTags) {
|
if (!hasCategories && !hasTags) {
|
||||||
posts = postRepository.findByStatusOrderByPinnedAtDescViewsDesc(PostStatus.PUBLISHED, pageable);
|
posts = postRepository.findByStatusOrderByViewsDesc(PostStatus.PUBLISHED);
|
||||||
} else if (hasCategories) {
|
} else if (hasCategories) {
|
||||||
java.util.List<Category> categories = categoryRepository.findAllById(categoryIds);
|
java.util.List<Category> categories = categoryRepository.findAllById(categoryIds);
|
||||||
if (categories.isEmpty()) {
|
if (categories.isEmpty()) {
|
||||||
@@ -824,18 +822,16 @@ public class PostService {
|
|||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
return java.util.List.of();
|
return java.util.List.of();
|
||||||
}
|
}
|
||||||
posts = postRepository.findByCategoriesAndAllTagsOrderByPinnedAtDescViewsDesc(
|
posts = postRepository.findByCategoriesAndAllTagsOrderByViewsDesc(
|
||||||
categories,
|
categories,
|
||||||
tags,
|
tags,
|
||||||
PostStatus.PUBLISHED,
|
PostStatus.PUBLISHED,
|
||||||
tags.size(),
|
tags.size()
|
||||||
pageable
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
posts = postRepository.findByCategoryInAndStatusOrderByPinnedAtDescViewsDesc(
|
posts = postRepository.findByCategoryInAndStatusOrderByViewsDesc(
|
||||||
categories,
|
categories,
|
||||||
PostStatus.PUBLISHED,
|
PostStatus.PUBLISHED
|
||||||
pageable
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -843,15 +839,10 @@ public class PostService {
|
|||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
return java.util.List.of();
|
return java.util.List.of();
|
||||||
}
|
}
|
||||||
posts = postRepository.findByAllTagsOrderByPinnedAtDescViewsDesc(
|
posts = postRepository.findByAllTagsOrderByViewsDesc(tags, PostStatus.PUBLISHED, tags.size());
|
||||||
tags,
|
|
||||||
PostStatus.PUBLISHED,
|
|
||||||
tags.size(),
|
|
||||||
pageable
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return posts;
|
return paginate(sortByPinnedAndViews(posts), page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Post> listPostsByLatestReply(Integer page, Integer pageSize) {
|
public List<Post> listPostsByLatestReply(Integer page, Integer pageSize) {
|
||||||
@@ -868,13 +859,9 @@ public class PostService {
|
|||||||
boolean hasTags = tagIds != null && !tagIds.isEmpty();
|
boolean hasTags = tagIds != null && !tagIds.isEmpty();
|
||||||
|
|
||||||
java.util.List<Post> posts;
|
java.util.List<Post> posts;
|
||||||
Pageable pageable = buildPageable(page, pageSize);
|
|
||||||
|
|
||||||
if (!hasCategories && !hasTags) {
|
if (!hasCategories && !hasTags) {
|
||||||
posts = postRepository.findByStatusOrderByPinnedAtDescLastReplyAtDesc(
|
posts = postRepository.findByStatusOrderByCreatedAtDesc(PostStatus.PUBLISHED);
|
||||||
PostStatus.PUBLISHED,
|
|
||||||
pageable
|
|
||||||
);
|
|
||||||
} else if (hasCategories) {
|
} else if (hasCategories) {
|
||||||
java.util.List<Category> categories = categoryRepository.findAllById(categoryIds);
|
java.util.List<Category> categories = categoryRepository.findAllById(categoryIds);
|
||||||
if (categories.isEmpty()) {
|
if (categories.isEmpty()) {
|
||||||
@@ -885,18 +872,16 @@ public class PostService {
|
|||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
return java.util.List.of();
|
return java.util.List.of();
|
||||||
}
|
}
|
||||||
posts = postRepository.findByCategoriesAndAllTagsOrderByPinnedAtDescLastReplyAtDesc(
|
posts = postRepository.findByCategoriesAndAllTagsOrderByCreatedAtDesc(
|
||||||
categories,
|
categories,
|
||||||
tags,
|
tags,
|
||||||
PostStatus.PUBLISHED,
|
PostStatus.PUBLISHED,
|
||||||
tags.size(),
|
tags.size()
|
||||||
pageable
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
posts = postRepository.findByCategoryInAndStatusOrderByPinnedAtDescLastReplyAtDesc(
|
posts = postRepository.findByCategoryInAndStatusOrderByCreatedAtDesc(
|
||||||
categories,
|
categories,
|
||||||
PostStatus.PUBLISHED,
|
PostStatus.PUBLISHED
|
||||||
pageable
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -904,15 +889,14 @@ public class PostService {
|
|||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
posts = postRepository.findByAllTagsOrderByPinnedAtDescLastReplyAtDesc(
|
posts = postRepository.findByAllTagsOrderByCreatedAtDesc(
|
||||||
tags,
|
tags,
|
||||||
PostStatus.PUBLISHED,
|
PostStatus.PUBLISHED,
|
||||||
tags.size(),
|
tags.size()
|
||||||
pageable
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return posts;
|
return paginate(sortByPinnedAndLastReply(posts), page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Post> listPostsByCategories(
|
public List<Post> listPostsByCategories(
|
||||||
@@ -1410,13 +1394,6 @@ public class PostService {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pageable buildPageable(Integer page, Integer pageSize) {
|
|
||||||
if (page == null || pageSize == null) {
|
|
||||||
return Pageable.unpaged();
|
|
||||||
}
|
|
||||||
return PageRequest.of(page, pageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Post> paginate(List<Post> posts, Integer page, Integer pageSize) {
|
private List<Post> paginate(List<Post> posts, Integer page, Integer pageSize) {
|
||||||
if (page == null || pageSize == null) {
|
if (page == null || pageSize == null) {
|
||||||
return posts;
|
return posts;
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
-- Backfill last_reply_at for posts without comments to preserve latest-reply ordering
|
|
||||||
UPDATE posts
|
|
||||||
SET last_reply_at = created_at
|
|
||||||
WHERE last_reply_at IS NULL;
|
|
||||||
@@ -30,62 +30,62 @@ services:
|
|||||||
- dev_local_backend
|
- dev_local_backend
|
||||||
- prod
|
- prod
|
||||||
|
|
||||||
# OpenSearch Service
|
# # OpenSearch Service
|
||||||
opensearch:
|
# opensearch:
|
||||||
user: "1000:1000"
|
# user: "1000:1000"
|
||||||
build:
|
# build:
|
||||||
context: .
|
# context: .
|
||||||
dockerfile: opensearch.Dockerfile
|
# dockerfile: opensearch.Dockerfile
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}-opensearch
|
# container_name: ${COMPOSE_PROJECT_NAME}-opensearch
|
||||||
environment:
|
# environment:
|
||||||
- cluster.name=os-single
|
# - cluster.name=os-single
|
||||||
- node.name=os-node-1
|
# - node.name=os-node-1
|
||||||
- discovery.type=single-node
|
# - discovery.type=single-node
|
||||||
- bootstrap.memory_lock=true
|
# - bootstrap.memory_lock=true
|
||||||
- OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
|
# - OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
|
||||||
- DISABLE_SECURITY_PLUGIN=true
|
# - DISABLE_SECURITY_PLUGIN=true
|
||||||
- cluster.blocks.create_index=false
|
# - cluster.blocks.create_index=false
|
||||||
ulimits:
|
# ulimits:
|
||||||
memlock: { soft: -1, hard: -1 }
|
# memlock: { soft: -1, hard: -1 }
|
||||||
nofile: { soft: 65536, hard: 65536 }
|
# nofile: { soft: 65536, hard: 65536 }
|
||||||
volumes:
|
# volumes:
|
||||||
- opensearch-data:/usr/share/opensearch/data
|
# - opensearch-data:/usr/share/opensearch/data
|
||||||
- opensearch-snapshots:/snapshots
|
# - opensearch-snapshots:/snapshots
|
||||||
ports:
|
# ports:
|
||||||
- "${OPENSEARCH_PORT:-9200}:9200"
|
# - "${OPENSEARCH_PORT:-9200}:9200"
|
||||||
- "${OPENSEARCH_METRICS_PORT:-9600}:9600"
|
# - "${OPENSEARCH_METRICS_PORT:-9600}:9600"
|
||||||
restart: unless-stopped
|
# restart: unless-stopped
|
||||||
healthcheck:
|
# healthcheck:
|
||||||
test:
|
# test:
|
||||||
- CMD-SHELL
|
# - CMD-SHELL
|
||||||
- curl -fsS http://127.0.0.1:9200/_cluster/health >/dev/null
|
# - curl -fsS http://127.0.0.1:9200/_cluster/health >/dev/null
|
||||||
interval: 10s
|
# interval: 10s
|
||||||
timeout: 5s
|
# timeout: 5s
|
||||||
retries: 30
|
# retries: 30
|
||||||
start_period: 60s
|
# start_period: 60s
|
||||||
networks:
|
# networks:
|
||||||
- openisle-network
|
# - openisle-network
|
||||||
profiles:
|
# profiles:
|
||||||
- dev
|
# - dev
|
||||||
- dev_local_backend
|
# - dev_local_backend
|
||||||
|
|
||||||
dashboards:
|
# dashboards:
|
||||||
image: opensearchproject/opensearch-dashboards:3.0.0
|
# image: opensearchproject/opensearch-dashboards:3.0.0
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}-os-dashboards
|
# container_name: ${COMPOSE_PROJECT_NAME}-os-dashboards
|
||||||
environment:
|
# environment:
|
||||||
OPENSEARCH_HOSTS: '["http://opensearch:9200"]'
|
# OPENSEARCH_HOSTS: '["http://opensearch:9200"]'
|
||||||
DISABLE_SECURITY_DASHBOARDS_PLUGIN: "true"
|
# DISABLE_SECURITY_DASHBOARDS_PLUGIN: "true"
|
||||||
ports:
|
# ports:
|
||||||
- "${OPENSEARCH_DASHBOARDS_PORT:-5601}:5601"
|
# - "${OPENSEARCH_DASHBOARDS_PORT:-5601}:5601"
|
||||||
depends_on:
|
# depends_on:
|
||||||
- opensearch
|
# - opensearch
|
||||||
restart: unless-stopped
|
# restart: unless-stopped
|
||||||
networks:
|
# networks:
|
||||||
- openisle-network
|
# - openisle-network
|
||||||
profiles:
|
# profiles:
|
||||||
- dev
|
# - dev
|
||||||
- dev_local_backend
|
# - dev_local_backend
|
||||||
- prod
|
# - prod
|
||||||
|
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
image: rabbitmq:3.13-management
|
image: rabbitmq:3.13-management
|
||||||
@@ -200,7 +200,6 @@ services:
|
|||||||
- openisle-network
|
- openisle-network
|
||||||
profiles:
|
profiles:
|
||||||
- dev
|
- dev
|
||||||
- dev_local_backend
|
|
||||||
- prod
|
- prod
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user