fix: タイムラインが読み込まれないのを修正

This commit is contained in:
usbharu 2023-10-12 02:32:33 +09:00
parent 3babce2f0c
commit 664b213346
1 changed files with 6 additions and 1 deletions

View File

@ -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<Status> {
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) })
}