Merge pull request #83 from usbharu/bugfix/fix-timeline

fix: タイムラインが読み込まれないのを修正
This commit is contained in:
usbharu 2023-10-12 10:53:26 +09:00 committed by GitHub
commit cae3759e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.domain.model.hideout.entity.Timeline
import dev.usbharu.hideout.query.mastodon.StatusQueryService import dev.usbharu.hideout.query.mastodon.StatusQueryService
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty 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.MongoTemplate
import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Query
@ -26,6 +27,7 @@ class MongoGenerateTimelineService(
limit: Int limit: Int
): List<Status> { ): List<Status> {
val query = Query() val query = Query()
if (forUserId != null) { if (forUserId != null) {
val criteria = Criteria.where("userId").`is`(forUserId) val criteria = Criteria.where("userId").`is`(forUserId)
query.addCriteria(criteria) query.addCriteria(criteria)
@ -43,7 +45,10 @@ class MongoGenerateTimelineService(
query.addCriteria(criteria) 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) }) return statusQueryService.findByPostIds(timelines.flatMap { setOfNotNull(it.postId, it.replyId, it.repostId) })
} }