Merge branch 'develop' into feature/remote-media

This commit is contained in:
usbharu 2023-11-02 20:01:17 +09:00 committed by GitHub
commit 8eead0d115
8 changed files with 30 additions and 11 deletions

View File

@ -132,6 +132,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.security:spring-security-oauth2-jose") implementation("org.springframework.security:spring-security-oauth2-jose")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb") implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.44.0") implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.44.0")
implementation("io.trbl:blurhash:1.0.0") implementation("io.trbl:blurhash:1.0.0")
implementation("software.amazon.awssdk:s3:2.20.157") implementation("software.amazon.awssdk:s3:2.20.157")

View File

@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository
@Repository @Repository
interface PostRepository { interface PostRepository {
suspend fun generateId(): Long suspend fun generateId(): Long
suspend fun save(post: Post): Post suspend fun save(post: Post): Boolean
suspend fun delete(id: Long) suspend fun delete(id: Long)
suspend fun findById(id: Long): Post suspend fun findById(id: Long): Post
} }

View File

@ -2,9 +2,11 @@ package dev.usbharu.hideout.core.domain.model.timeline
import dev.usbharu.hideout.core.domain.model.post.Visibility import dev.usbharu.hideout.core.domain.model.post.Visibility
import org.springframework.data.annotation.Id import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.mapping.Document import org.springframework.data.mongodb.core.mapping.Document
@Document @Document
@CompoundIndex(def = "{'userId':1,'timelineId':1,'postId':1}", unique = true)
data class Timeline( data class Timeline(
@Id @Id
val id: Long, val id: Long,

View File

@ -17,7 +17,7 @@ class PostRepositoryImpl(
override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun generateId(): Long = idGenerateService.generateId()
override suspend fun save(post: Post): Post { override suspend fun save(post: Post): Boolean {
val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull() val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull()
if (singleOrNull == null) { if (singleOrNull == null) {
Posts.insert { Posts.insert {
@ -63,7 +63,7 @@ class PostRepositoryImpl(
"Faild to insert" "Faild to insert"
} }
return post return singleOrNull == null
} }
override suspend fun findById(id: Long): Post = override suspend fun findById(id: Long): Post =

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.core.infrastructure.kjobmongodb package dev.usbharu.hideout.core.infrastructure.kjobmongodb
import com.mongodb.reactivestreams.client.MongoClient
import dev.usbharu.hideout.core.service.job.JobQueueWorkerService import dev.usbharu.hideout.core.service.job.JobQueueWorkerService
import kjob.core.dsl.JobRegisterContext import kjob.core.dsl.JobRegisterContext
import kjob.core.dsl.KJobFunctions import kjob.core.dsl.KJobFunctions
@ -12,10 +13,10 @@ import kjob.core.dsl.JobContextWithProps as JCWP
@Service @Service
@ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false)
class KJobMongoJobQueueWorkerService : JobQueueWorkerService { class KJobMongoJobQueueWorkerService(private val mongoClient: MongoClient) : JobQueueWorkerService, AutoCloseable {
val kjob by lazy { val kjob by lazy {
kjob(Mongo) { kjob(Mongo) {
connectionString = "mongodb://localhost" client = mongoClient
nonBlockingMaxJobs = 10 nonBlockingMaxJobs = 10
blockingMaxJobs = 10 blockingMaxJobs = 10
jobExecutionPeriodInSeconds = 1 jobExecutionPeriodInSeconds = 1
@ -29,4 +30,8 @@ class KJobMongoJobQueueWorkerService : JobQueueWorkerService {
kjob.register(job.first, job.second) kjob.register(job.first, job.second)
} }
} }
override fun close() {
kjob.shutdown()
}
} }

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.core.infrastructure.kjobmongodb package dev.usbharu.hideout.core.infrastructure.kjobmongodb
import com.mongodb.reactivestreams.client.MongoClient
import dev.usbharu.hideout.core.service.job.JobQueueParentService import dev.usbharu.hideout.core.service.job.JobQueueParentService
import kjob.core.Job import kjob.core.Job
import kjob.core.dsl.ScheduleContext import kjob.core.dsl.ScheduleContext
@ -10,9 +11,9 @@ import org.springframework.stereotype.Service
@Service @Service
@ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(name = ["hideout.use-mongodb"], havingValue = "true", matchIfMissing = false)
class KjobMongoJobQueueParentService : JobQueueParentService { class KjobMongoJobQueueParentService(private val mongoClient: MongoClient) : JobQueueParentService, AutoCloseable {
private val kjob = kjob(Mongo) { private val kjob = kjob(Mongo) {
connectionString = "mongodb://localhost" client = mongoClient
databaseName = "kjob" databaseName = "kjob"
jobCollection = "kjob-jobs" jobCollection = "kjob-jobs"
lockCollection = "kjob-locks" lockCollection = "kjob-locks"
@ -25,4 +26,8 @@ class KjobMongoJobQueueParentService : JobQueueParentService {
override suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit) { override suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit) {
kjob.schedule(job, block) kjob.schedule(job, block)
} }
override fun close() {
kjob.shutdown()
}
} }

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.core.service.post package dev.usbharu.hideout.core.service.post
import com.mongodb.DuplicateKeyException
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
import dev.usbharu.hideout.core.domain.exception.UserNotFoundException import dev.usbharu.hideout.core.domain.exception.UserNotFoundException
import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.Post
@ -38,13 +39,17 @@ class PostServiceImpl(
} }
private suspend fun internalCreate(post: Post, isLocal: Boolean): Post { private suspend fun internalCreate(post: Post, isLocal: Boolean): Post {
val save = try { return try {
postRepository.save(post) if (postRepository.save(post)) {
try {
timelineService.publishTimeline(post, isLocal)
} catch (_: DuplicateKeyException) {
}
}
post
} catch (_: ExposedSQLException) { } catch (_: ExposedSQLException) {
postQueryService.findByApId(post.apId) postQueryService.findByApId(post.apId)
} }
timelineService.publishTimeline(save, isLocal)
return save
} }
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post { private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {

View File

@ -24,6 +24,7 @@ spring:
password: "" password: ""
data: data:
mongodb: mongodb:
auto-index-creation: true
host: localhost host: localhost
port: 27017 port: 27017
database: hideout database: hideout