mirror of https://github.com/usbharu/Hideout.git
fix: タイムラインが重複する現象を修正
This commit is contained in:
parent
38b34b0424
commit
4b935b8c12
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue