diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt index 5ee4c5f1..96637607 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.domain.model.relationship import dev.usbharu.hideout.application.infrastructure.exposed.Page import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList import dev.usbharu.hideout.application.infrastructure.exposed.pagination +import dev.usbharu.hideout.application.infrastructure.exposed.withPagination import dev.usbharu.hideout.core.infrastructure.exposedrepository.AbstractRepository import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors import org.jetbrains.exposed.dao.id.LongIdTable @@ -87,12 +88,12 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() .and(Relationships.ignoreFollowRequestFromTarget.eq(ignoreFollowRequest)) } - val resultRowList = query.pagination(page, Relationships.id).toList() + val resultRowList = query.withPagination(page, Relationships.id) return@query PaginationList( - query.map { it.toRelationships() }, - resultRowList.lastOrNull()?.getOrNull(Relationships.id)?.value, - resultRowList.firstOrNull()?.getOrNull(Relationships.id)?.value + resultRowList.map { it.toRelationships() }, + resultRowList.next?.value, + resultRowList.prev?.value ) } @@ -105,12 +106,12 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() Relationships.actorId.eq(actorId).and(Relationships.muting.eq(muting)) } - val resultRowList = query.pagination(page, Relationships.id).toList() + val resultRowList = query.withPagination(page, Relationships.id) return@query PaginationList( - query.map { it.toRelationships() }, - resultRowList.lastOrNull()?.getOrNull(Relationships.id)?.value, - resultRowList.firstOrNull()?.getOrNull(Relationships.id)?.value + resultRowList.map { it.toRelationships() }, + resultRowList.next?.value, + resultRowList.prev?.value ) } 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 42eedaaa..ce0bb389 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 @@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.service.timeline import dev.usbharu.hideout.application.infrastructure.exposed.Page import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList import dev.usbharu.hideout.application.infrastructure.exposed.pagination +import dev.usbharu.hideout.application.infrastructure.exposed.withPagination import dev.usbharu.hideout.core.infrastructure.exposedrepository.Timelines import dev.usbharu.hideout.domain.mastodon.model.generated.Status import dev.usbharu.hideout.mastodon.interfaces.api.status.StatusQuery @@ -31,9 +32,8 @@ class ExposedGenerateTimelineService(private val statusQueryService: StatusQuery if (localOnly) { query.andWhere { Timelines.isLocal eq true } } - query.pagination(page, Timelines.id) - val result = query - .orderBy(Timelines.createdAt, SortOrder.DESC) + val result = query.withPagination(page, Timelines.id) + val statusQueries = result.map { StatusQuery( diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt index de7bd9ea..5d0589fa 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.exposedquery import dev.usbharu.hideout.application.infrastructure.exposed.Page import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList import dev.usbharu.hideout.application.infrastructure.exposed.pagination +import dev.usbharu.hideout.application.infrastructure.exposed.withPagination import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji import dev.usbharu.hideout.core.domain.model.media.toMediaAttachments import dev.usbharu.hideout.core.infrastructure.exposedrepository.* @@ -71,8 +72,6 @@ class StatusQueryServiceImpl : StatusQueryService { .leftJoin(Media) .select { Posts.actorId eq accountId } - query.pagination(page, Posts.id) - if (onlyMedia) { query.andWhere { PostsMedia.mediaId.isNotNull() } } @@ -88,7 +87,9 @@ class StatusQueryServiceImpl : StatusQueryService { query.andWhere { Posts.visibility inList listOf(public.ordinal, unlisted.ordinal) } } - val pairs = query.groupBy { it[Posts.id] } + val pairs = query + .withPagination(page,Posts.id) + .groupBy { it[Posts.id] } .map { it.value } .map { toStatus(it.first()).copy( diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt index bc62b656..2aacff1e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.exposedrepository import dev.usbharu.hideout.application.infrastructure.exposed.Page import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList import dev.usbharu.hideout.application.infrastructure.exposed.pagination +import dev.usbharu.hideout.application.infrastructure.exposed.withPagination import dev.usbharu.hideout.core.infrastructure.exposedrepository.AbstractRepository import dev.usbharu.hideout.core.infrastructure.exposedrepository.Timelines import dev.usbharu.hideout.mastodon.domain.model.MastodonNotification @@ -71,12 +72,9 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab val query = MastodonNotifications.select { MastodonNotifications.userId eq loginUser } - val result = query - .pagination(page, MastodonNotifications.id) - .orderBy(Timelines.createdAt, SortOrder.DESC) + val result = query.withPagination(page, MastodonNotifications.id) - val notifications = result.map { it.toMastodonNotification() } - return@query PaginationList(notifications, notifications.lastOrNull()?.id, notifications.firstOrNull()?.id) + return@query PaginationList(result.map { it.toMastodonNotification() }, result.next, result.prev) } override suspend fun deleteByUserId(userId: Long) {