mirror of https://github.com/usbharu/Hideout.git
feat: トランザクションを調整
This commit is contained in:
parent
269289966c
commit
53936455c1
|
@ -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<User> =
|
||||
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<Long>): List<User> =
|
||||
Users.select { Users.id inList ids }.map { it.toUser() }
|
||||
|
|
|
@ -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, "")
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -6,7 +6,13 @@ import org.koin.core.annotation.Single
|
|||
@Single
|
||||
class ExposedTransaction : Transaction {
|
||||
override suspend fun <T> transaction(block: suspend () -> T): T {
|
||||
return newSuspendedTransaction {
|
||||
return newSuspendedTransaction(transactionIsolation = java.sql.Connection.TRANSACTION_SERIALIZABLE) {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> transaction(transactionLevel: Int, block: suspend () -> T): T {
|
||||
return newSuspendedTransaction(transactionIsolation = transactionLevel) {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@ package dev.usbharu.hideout.service.core
|
|||
|
||||
interface Transaction {
|
||||
suspend fun <T> transaction(block: suspend () -> T): T
|
||||
suspend fun <T> transaction(transactionLevel: Int, block: suspend () -> T): T
|
||||
}
|
||||
|
|
|
@ -4,4 +4,5 @@ import dev.usbharu.hideout.service.core.Transaction
|
|||
|
||||
object TestTransaction : Transaction {
|
||||
override suspend fun <T> transaction(block: suspend () -> T): T = block()
|
||||
override suspend fun <T> transaction(transactionLevel: Int, block: suspend () -> T): T = block()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue