diff --git a/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt index 9d18d2cd..647b8d5f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/query/UserQueryServiceImpl.kt @@ -9,9 +9,13 @@ import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.koin.core.annotation.Single +import org.slf4j.LoggerFactory @Single class UserQueryServiceImpl : UserQueryService { + + private val logger = LoggerFactory.getLogger(UserQueryServiceImpl::class.java) + override suspend fun findAll(limit: Int, offset: Long): List = Users.selectAll().limit(limit, offset).map { it.toUser() } @@ -28,9 +32,12 @@ class UserQueryServiceImpl : UserQueryService { } .toUser() - override suspend fun findByUrl(url: String): User = Users.select { Users.url eq url } - .singleOr { FailedToGetResourcesException("url: $url is duplicate or does not exist.", it) } - .toUser() + override suspend fun findByUrl(url: String): User { + logger.trace("findByUrl url: $url") + return Users.select { Users.url eq url } + .singleOr { FailedToGetResourcesException("url: $url is duplicate or does not exist.", it) } + .toUser() + } override suspend fun findByIds(ids: List): List = Users.select { Users.id inList ids }.map { it.toUser() } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt index 0313acf8..6f88d87a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt @@ -28,18 +28,19 @@ class APLikeServiceImpl( val actor = like.actor ?: throw IllegalActivityPubObjectException("actor is null") val content = like.content ?: throw IllegalActivityPubObjectException("content is null") like.`object` ?: throw IllegalActivityPubObjectException("object is null") - transaction.transaction { - val person = apUserService.fetchPerson(actor) + transaction.transaction(java.sql.Connection.TRANSACTION_SERIALIZABLE) { + val person = apUserService.fetchPersonWithEntity(actor) apNoteService.fetchNote(like.`object`!!) - val user = userQueryService.findByUrl( - person.url - ?: throw IllegalActivityPubObjectException("actor is not found") - ) val post = postQueryService.findByUrl(like.`object`!!) - reactionService.receiveReaction(content, actor.substringAfter("://").substringBefore("/"), user.id, post.id) + reactionService.receiveReaction( + content, + actor.substringAfter("://").substringBefore("/"), + person.second.id, + post.id + ) } return ActivityPubStringResponse(HttpStatusCode.OK, "") } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 255c9804..45583001 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -120,7 +120,8 @@ class APNoteServiceImpl( url: String ): Note { if (note.id == null) { - return internalNote(note, targetActor, url) + throw IllegalArgumentException("id is null") +// return internalNote(note, targetActor, url) } val findByApId = try { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt index a58cfe04..c15327a4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/ExposedTransaction.kt @@ -6,7 +6,13 @@ import org.koin.core.annotation.Single @Single class ExposedTransaction : Transaction { override suspend fun transaction(block: suspend () -> T): T { - return newSuspendedTransaction { + return newSuspendedTransaction(transactionIsolation = java.sql.Connection.TRANSACTION_SERIALIZABLE) { + block() + } + } + + override suspend fun transaction(transactionLevel: Int, block: suspend () -> T): T { + return newSuspendedTransaction(transactionIsolation = transactionLevel) { block() } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/Transaction.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/Transaction.kt index 40911be1..105420ed 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/Transaction.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/Transaction.kt @@ -2,4 +2,5 @@ package dev.usbharu.hideout.service.core interface Transaction { suspend fun transaction(block: suspend () -> T): T + suspend fun transaction(transactionLevel: Int, block: suspend () -> T): T } diff --git a/src/test/kotlin/utils/TestTransaction.kt b/src/test/kotlin/utils/TestTransaction.kt index 425372bd..f8d1832c 100644 --- a/src/test/kotlin/utils/TestTransaction.kt +++ b/src/test/kotlin/utils/TestTransaction.kt @@ -4,4 +4,5 @@ import dev.usbharu.hideout.service.core.Transaction object TestTransaction : Transaction { override suspend fun transaction(block: suspend () -> T): T = block() + override suspend fun transaction(transactionLevel: Int, block: suspend () -> T): T = block() }