From 43a4fa3ca6a12975dfcba2b1c5fed3174f0b4d1a Mon Sep 17 00:00:00 2001 From: li-guohao <46225881+li-guohao@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:52:53 +0800 Subject: [PATCH] optimize: list api default order for attachment and subject episode and attachment ref. (#508) --- CHANGELOG.MD | 24 ++++++++++++------- .../service/impl/AttachmentServiceImpl.java | 5 +++- .../service/impl/SubjectServiceImpl.java | 12 ++++++---- .../AttachmentReferenceRepository.java | 3 +++ .../store/repository/EpisodeRepository.java | 3 +++ 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 22ea23ba7..e50bc75a6 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -2,6 +2,18 @@ 更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。 +# 0.11.7 + +## 优化 + +- [WIP] 条目收藏形式优化,一次性提交收藏类型和标签 + +## 插件 + +### 番组计划 + +- [WIP] 拉取条目时,转换对应的标签 + # 0.11.6 ## 新特性 @@ -13,14 +25,10 @@ ## 优化 - 条目详情页,给番组集合平台加上对应的条目详情URL前缀 -- [WIP] 列表接口排序优化#506 -- [WIP] 条目收藏形式优化,一次性提交收藏类型和标签 - -## 插件 - -### 番组计划 - -- [WIP] 拉取条目时,转换对应的标签 +- 列表接口排序优化 #506 指定默认排序规则 + - 附件列表接口,按类型、名称、大小、更新时间依次升序 + - 条目剧集列表接口,按分组降序,序号、放送时间、创建时间依次升序 + - 剧集附件引用列表接口,在根据参数放送时间排序后,按名称、类型、NSFW依次升序 # 0.11.5 diff --git a/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java b/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java index 636694b35..89d4d0589 100644 --- a/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java +++ b/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java @@ -138,7 +138,10 @@ public Mono> listEntitiesByCondition( } Query query = Query.query(criteria) - .sort(Sort.by(Sort.Order.by("type"))) + .sort(Sort.by(Sort.Order.asc("type"))) + .sort(Sort.by(Sort.Order.asc("name"))) + .sort(Sort.by(Sort.Order.asc("size"))) + .sort(Sort.by(Sort.Order.asc("update_time"))) .with(pageRequest); Flux attachmentEntityFlux = diff --git a/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java b/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java index 07f488b16..6f9ade39b 100644 --- a/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java +++ b/server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java @@ -6,7 +6,6 @@ import jakarta.annotation.Nonnull; import jakarta.validation.constraints.NotBlank; import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -106,9 +105,12 @@ public Mono findById(Long id) { .flatMap(subjectEntity -> copyProperties(subjectEntity, new Subject())) .checkpoint("FindSubjectEntityById") - .flatMap(subject -> episodeRepository.findAllBySubjectId(subject.getId()) + .flatMap(subject -> episodeRepository + .findAllBySubjectIdOrderByGroupDescSequenceAscAirTimeAscCreateTimeAsc( + subject.getId()) .flatMap(episodeEntity -> copyProperties(episodeEntity, new Episode())) - .flatMap(episode -> attachmentReferenceRepository.findAllByTypeAndReferenceId( + .flatMap(episode -> attachmentReferenceRepository + .findAllByTypeAndReferenceIdOrderByTypeAscAttachmentIdAsc( AttachmentReferenceType.EPISODE, episode.getId()) .flatMap(attachmentReferenceEntity -> attachmentRepository.findById(attachmentReferenceEntity.getAttachmentId()) @@ -122,7 +124,6 @@ public Mono findById(Long id) { .build()) ).collectList() .map(episode::setResources)) - .sort(Comparator.comparingDouble(Episode::getSequence)) .collectList() .map(episodes -> subject .setTotalEpisodes((long) episodes.size()) @@ -374,6 +375,9 @@ public Mono> listEntitiesByCondition(FindSubjectConditio .sort(Sort.by(airTimeDesc ? Sort.Order.desc("air_time") : Sort.Order.asc("air_time"))) + .sort(Sort.by(Sort.Order.asc("name"))) + .sort(Sort.by(Sort.Order.asc("type"))) + .sort(Sort.by(Sort.Order.asc("nsfw"))) .with(pageRequest); Flux subjectEntityFlux = template.select(query, SubjectEntity.class); diff --git a/server/src/main/java/run/ikaros/server/store/repository/AttachmentReferenceRepository.java b/server/src/main/java/run/ikaros/server/store/repository/AttachmentReferenceRepository.java index b7bd3eded..87ceda757 100644 --- a/server/src/main/java/run/ikaros/server/store/repository/AttachmentReferenceRepository.java +++ b/server/src/main/java/run/ikaros/server/store/repository/AttachmentReferenceRepository.java @@ -25,6 +25,9 @@ Mono findByTypeAndAttachmentIdAndReferenceId( Flux findAllByTypeAndReferenceId(AttachmentReferenceType type, Long referenceId); + Flux findAllByTypeAndReferenceIdOrderByTypeAscAttachmentIdAsc( + AttachmentReferenceType type, Long referenceId); + Mono deleteByTypeAndAttachmentIdAndReferenceId( AttachmentReferenceType type, Long attachmentId, Long referenceId); diff --git a/server/src/main/java/run/ikaros/server/store/repository/EpisodeRepository.java b/server/src/main/java/run/ikaros/server/store/repository/EpisodeRepository.java index 196478ab8..f94d5eff0 100644 --- a/server/src/main/java/run/ikaros/server/store/repository/EpisodeRepository.java +++ b/server/src/main/java/run/ikaros/server/store/repository/EpisodeRepository.java @@ -9,6 +9,9 @@ public interface EpisodeRepository extends R2dbcRepository { Flux findAllBySubjectId(Long subjectId); + Flux findAllBySubjectIdOrderByGroupDescSequenceAscAirTimeAscCreateTimeAsc( + Long subjectId); + Mono deleteAllBySubjectId(Long subjectId); Mono findBySubjectIdAndGroupAndSequence(Long subjectId, EpisodeGroup group,