mirror of https://github.com/usbharu/Hideout.git
feat: 明示的にフォロワー/フォロイー/投稿の数を更新する関数を追加
This commit is contained in:
parent
a242748908
commit
0779c92ec4
|
@ -30,4 +30,6 @@ interface PostRepository {
|
||||||
suspend fun findByApId(apId: String): Post?
|
suspend fun findByApId(apId: String): Post?
|
||||||
suspend fun existByApIdWithLock(apId: String): Boolean
|
suspend fun existByApIdWithLock(apId: String): Boolean
|
||||||
suspend fun findByActorId(actorId: Long): List<Post>
|
suspend fun findByActorId(actorId: Long): List<Post>
|
||||||
|
|
||||||
|
suspend fun countByActorId(actorId: Long): Int
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,21 @@ interface RelationshipRepository {
|
||||||
|
|
||||||
suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship>
|
suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship>
|
||||||
|
|
||||||
|
suspend fun countByTargetIdAndFollowing(targetId: Long, following: Boolean): Int
|
||||||
|
|
||||||
|
suspend fun countByUserIdAndFollowing(targetId: Long, following: Boolean): Int
|
||||||
|
|
||||||
@Suppress("FunctionMaxLength")
|
@Suppress("FunctionMaxLength")
|
||||||
suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest(
|
suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest(
|
||||||
targetId: Long,
|
targetId: Long,
|
||||||
followRequest: Boolean,
|
followRequest: Boolean,
|
||||||
ignoreFollowRequest: Boolean,
|
ignoreFollowRequest: Boolean,
|
||||||
page: Page.PageByMaxId
|
page: Page.PageByMaxId,
|
||||||
): PaginationList<Relationship, Long>
|
): PaginationList<Relationship, Long>
|
||||||
|
|
||||||
suspend fun findByActorIdAndMuting(
|
suspend fun findByActorIdAndMuting(
|
||||||
actorId: Long,
|
actorId: Long,
|
||||||
muting: Boolean,
|
muting: Boolean,
|
||||||
page: Page.PageByMaxId
|
page: Page.PageByMaxId,
|
||||||
): PaginationList<Relationship, Long>
|
): PaginationList<Relationship, Long>
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,6 @@ interface UserService {
|
||||||
suspend fun deleteRemoteActor(actorId: Long)
|
suspend fun deleteRemoteActor(actorId: Long)
|
||||||
|
|
||||||
suspend fun deleteLocalUser(userId: Long)
|
suspend fun deleteLocalUser(userId: Long)
|
||||||
|
|
||||||
|
suspend fun updateUserStatistics(userId: Long)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.deletedActor.DeletedActor
|
import dev.usbharu.hideout.core.domain.model.deletedActor.DeletedActor
|
||||||
import dev.usbharu.hideout.core.domain.model.deletedActor.DeletedActorRepository
|
import dev.usbharu.hideout.core.domain.model.deletedActor.DeletedActorRepository
|
||||||
|
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
|
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
|
||||||
|
@ -47,8 +48,8 @@ class UserServiceImpl(
|
||||||
private val reactionRepository: ReactionRepository,
|
private val reactionRepository: ReactionRepository,
|
||||||
private val relationshipRepository: RelationshipRepository,
|
private val relationshipRepository: RelationshipRepository,
|
||||||
private val postService: PostService,
|
private val postService: PostService,
|
||||||
private val apSendDeleteService: APSendDeleteService
|
private val apSendDeleteService: APSendDeleteService,
|
||||||
|
private val postRepository: PostRepository,
|
||||||
) :
|
) :
|
||||||
UserService {
|
UserService {
|
||||||
|
|
||||||
|
@ -191,6 +192,22 @@ class UserServiceImpl(
|
||||||
deletedActorRepository.save(deletedActor)
|
deletedActorRepository.save(deletedActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateUserStatistics(userId: Long) {
|
||||||
|
val actor = actorRepository.findByIdWithLock(userId) ?: throw UserNotFoundException.withId(userId)
|
||||||
|
|
||||||
|
val followerCount = relationshipRepository.countByTargetIdAndFollowing(userId, true)
|
||||||
|
val followingCount = relationshipRepository.countByUserIdAndFollowing(userId, true)
|
||||||
|
val postsCount = postRepository.countByActorId(userId)
|
||||||
|
|
||||||
|
actorRepository.save(
|
||||||
|
actor.copy(
|
||||||
|
followersCount = followerCount,
|
||||||
|
followingCount = followingCount,
|
||||||
|
postsCount = postsCount
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val logger = LoggerFactory.getLogger(UserServiceImpl::class.java)
|
private val logger = LoggerFactory.getLogger(UserServiceImpl::class.java)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue