mirror of https://github.com/usbharu/Hideout.git
Merge pull request #133 from usbharu/bugfix/timeline-duplicate
fix: タイムラインが重複する現象を修正
This commit is contained in:
commit
c4c7ae92e0
|
@ -6,7 +6,7 @@ import org.springframework.stereotype.Repository
|
|||
@Repository
|
||||
interface PostRepository {
|
||||
suspend fun generateId(): Long
|
||||
suspend fun save(post: Post): Post
|
||||
suspend fun save(post: Post): Boolean
|
||||
suspend fun delete(id: Long)
|
||||
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 org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
|
||||
@Document
|
||||
@CompoundIndex(def = "{'userId':1,'timelineId':1,'postId':1}", unique = true)
|
||||
data class Timeline(
|
||||
@Id
|
||||
val id: Long,
|
||||
|
|
|
@ -17,7 +17,7 @@ class PostRepositoryImpl(
|
|||
|
||||
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()
|
||||
if (singleOrNull == null) {
|
||||
Posts.insert {
|
||||
|
@ -63,7 +63,7 @@ class PostRepositoryImpl(
|
|||
"Faild to insert"
|
||||
}
|
||||
|
||||
return post
|
||||
return singleOrNull == null
|
||||
}
|
||||
|
||||
override suspend fun findById(id: Long): Post =
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.core.service.post
|
||||
|
||||
import com.mongodb.DuplicateKeyException
|
||||
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
||||
import dev.usbharu.hideout.core.domain.exception.UserNotFoundException
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
|
@ -38,13 +39,17 @@ class PostServiceImpl(
|
|||
}
|
||||
|
||||
private suspend fun internalCreate(post: Post, isLocal: Boolean): Post {
|
||||
val save = try {
|
||||
postRepository.save(post)
|
||||
return try {
|
||||
if (postRepository.save(post)) {
|
||||
try {
|
||||
timelineService.publishTimeline(post, isLocal)
|
||||
} catch (_: DuplicateKeyException) {
|
||||
}
|
||||
}
|
||||
post
|
||||
} catch (_: ExposedSQLException) {
|
||||
postQueryService.findByApId(post.apId)
|
||||
}
|
||||
timelineService.publishTimeline(save, isLocal)
|
||||
return save
|
||||
}
|
||||
|
||||
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
||||
|
|
|
@ -24,6 +24,7 @@ spring:
|
|||
password: ""
|
||||
data:
|
||||
mongodb:
|
||||
auto-index-creation: true
|
||||
host: localhost
|
||||
port: 27017
|
||||
database: hideout
|
||||
|
|
Loading…
Reference in New Issue