diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt index d4f8e1af..42eedaaa 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/ExposedGenerateTimelineService.kt @@ -16,45 +16,6 @@ import org.springframework.stereotype.Service @Service @ConditionalOnProperty("hideout.use-mongodb", havingValue = "false", matchIfMissing = true) class ExposedGenerateTimelineService(private val statusQueryService: StatusQueryService) : GenerateTimelineService { - override suspend fun getTimeline( - forUserId: Long?, - localOnly: Boolean, - mediaOnly: Boolean, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int - ): List { - val query = Timelines.selectAll() - - if (forUserId != null) { - query.andWhere { Timelines.userId eq forUserId } - } - if (localOnly) { - query.andWhere { Timelines.isLocal eq true } - } - if (maxId != null) { - query.andWhere { Timelines.id lessEq maxId } - } - if (minId != null) { - query.andWhere { Timelines.id greaterEq minId } - } - val result = query - .limit(limit) - .orderBy(Timelines.createdAt, SortOrder.DESC) - - val statusQueries = result.map { - StatusQuery( - it[Timelines.postId], - it[Timelines.replyId], - it[Timelines.repostId], - it[Timelines.mediaIds].split(",").mapNotNull { s -> s.toLongOrNull() }, - it[Timelines.emojiIds].split(",").mapNotNull { s -> s.toLongOrNull() } - ) - } - - return statusQueryService.findByPostIdsWithMediaIds(statusQueries) - } override suspend fun getTimeline( forUserId: Long?, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt index 4e21c285..50ab6271 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/GenerateTimelineService.kt @@ -8,15 +8,6 @@ import org.springframework.stereotype.Service @Service @Suppress("LongParameterList") interface GenerateTimelineService { - suspend fun getTimeline( - forUserId: Long? = null, - localOnly: Boolean = false, - mediaOnly: Boolean = false, - maxId: Long? = null, - minId: Long? = null, - sinceId: Long? = null, - limit: Int = 20 - ): List suspend fun getTimeline( forUserId: Long? = null, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt index 7cc7938f..c9bb7618 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/timeline/MongoGenerateTimelineService.kt @@ -20,51 +20,6 @@ class MongoGenerateTimelineService( private val mongoTemplate: MongoTemplate ) : GenerateTimelineService { - override suspend fun getTimeline( - forUserId: Long?, - localOnly: Boolean, - mediaOnly: Boolean, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int - ): List { - val query = Query() - - if (forUserId != null) { - val criteria = Criteria.where("userId").`is`(forUserId) - query.addCriteria(criteria) - } - if (localOnly) { - val criteria = Criteria.where("isLocal").`is`(true) - query.addCriteria(criteria) - } - if (maxId != null) { - val criteria = Criteria.where("postId").lt(maxId) - query.addCriteria(criteria) - } - if (minId != null) { - val criteria = Criteria.where("postId").gt(minId) - query.addCriteria(criteria) - } - - query.limit(limit) - query.with(Sort.by(Sort.Direction.DESC, "createdAt")) - - val timelines = mongoTemplate.find(query, Timeline::class.java) - - return statusQueryService.findByPostIdsWithMediaIds( - timelines.map { - StatusQuery( - it.postId, - it.replyId, - it.repostId, - it.mediaIds, - it.emojiIds - ) - } - ) - } override suspend fun getTimeline( forUserId: Long?, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/timeline/TimelineApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/timeline/TimelineApiService.kt index 9d11b8ac..7a409584 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/timeline/TimelineApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/timeline/TimelineApiService.kt @@ -9,15 +9,6 @@ import org.springframework.stereotype.Service @Suppress("LongParameterList") interface TimelineApiService { - suspend fun publicTimeline( - localOnly: Boolean = false, - remoteOnly: Boolean = false, - mediaOnly: Boolean = false, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int = 20 - ): List suspend fun publicTimeline( localOnly: Boolean = false, @@ -26,14 +17,6 @@ interface TimelineApiService { page: Page ): PaginationList - suspend fun homeTimeline( - userId: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int = 20 - ): List - suspend fun homeTimeline( userId: Long, page: Page @@ -45,49 +28,18 @@ class TimelineApiServiceImpl( private val generateTimelineService: GenerateTimelineService, private val transaction: Transaction ) : TimelineApiService { - override suspend fun publicTimeline( - localOnly: Boolean, - remoteOnly: Boolean, - mediaOnly: Boolean, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int - ): List = transaction.transaction { - generateTimelineService.getTimeline( - forUserId = 0, - localOnly = localOnly, - mediaOnly = mediaOnly, - maxId = maxId, - minId = minId, - sinceId = sinceId, - limit = limit - ) - } override suspend fun publicTimeline( localOnly: Boolean, remoteOnly: Boolean, mediaOnly: Boolean, page: Page - ): PaginationList = generateTimelineService.getTimeline(forUserId = 0, localOnly, mediaOnly, page) - - override suspend fun homeTimeline( - userId: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int - ): List = transaction.transaction { - generateTimelineService.getTimeline( - forUserId = userId, - maxId = maxId, - minId = minId, - sinceId = sinceId, - limit = limit - ) + ): PaginationList = transaction.transaction { + return@transaction generateTimelineService.getTimeline(forUserId = 0, localOnly, mediaOnly, page) } override suspend fun homeTimeline(userId: Long, page: Page): PaginationList = - generateTimelineService.getTimeline(forUserId = userId, page = page) + transaction.transaction { + return@transaction generateTimelineService.getTimeline(forUserId = userId, page = page) + } }