From 664b2133463585b53a442cfd12916cd4c7c657cb Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 12 Oct 2023 02:32:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=8C=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=81=BE?= =?UTF-8?q?=E3=82=8C=E3=81=AA=E3=81=84=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/service/post/MongoGenerateTimelineService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/MongoGenerateTimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/MongoGenerateTimelineService.kt index 098e17ca..0a677430 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/MongoGenerateTimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/MongoGenerateTimelineService.kt @@ -4,6 +4,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Status import dev.usbharu.hideout.domain.model.hideout.entity.Timeline import dev.usbharu.hideout.query.mastodon.StatusQueryService import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.data.domain.Sort import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query @@ -26,6 +27,7 @@ class MongoGenerateTimelineService( limit: Int ): List { val query = Query() + if (forUserId != null) { val criteria = Criteria.where("userId").`is`(forUserId) query.addCriteria(criteria) @@ -43,7 +45,10 @@ class MongoGenerateTimelineService( query.addCriteria(criteria) } - val timelines = mongoTemplate.find(query.limit(limit), Timeline::class.java) + query.limit(limit) + query.with(Sort.by(Sort.Direction.DESC, "createdAt")) + + val timelines = mongoTemplate.find(query, Timeline::class.java) return statusQueryService.findByPostIds(timelines.flatMap { setOfNotNull(it.postId, it.replyId, it.repostId) }) }