refactor: 不要になった関数を削除

This commit is contained in:
usbharu 2024-01-29 20:30:35 +09:00
parent b63288ff28
commit c0a7c2da34
4 changed files with 5 additions and 146 deletions

View File

@ -16,45 +16,6 @@ import org.springframework.stereotype.Service
@Service @Service
@ConditionalOnProperty("hideout.use-mongodb", havingValue = "false", matchIfMissing = true) @ConditionalOnProperty("hideout.use-mongodb", havingValue = "false", matchIfMissing = true)
class ExposedGenerateTimelineService(private val statusQueryService: StatusQueryService) : GenerateTimelineService { class ExposedGenerateTimelineService(private val statusQueryService: StatusQueryService) : GenerateTimelineService {
override suspend fun getTimeline(
forUserId: Long?,
localOnly: Boolean,
mediaOnly: Boolean,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int
): List<Status> {
val query = Timelines.selectAll()
if (forUserId != null) {
query.andWhere { Timelines.userId eq forUserId }
}
if (localOnly) {
query.andWhere { Timelines.isLocal eq true }
}
if (maxId != null) {
query.andWhere { Timelines.id lessEq maxId }
}
if (minId != null) {
query.andWhere { Timelines.id greaterEq minId }
}
val result = query
.limit(limit)
.orderBy(Timelines.createdAt, SortOrder.DESC)
val statusQueries = result.map {
StatusQuery(
it[Timelines.postId],
it[Timelines.replyId],
it[Timelines.repostId],
it[Timelines.mediaIds].split(",").mapNotNull { s -> s.toLongOrNull() },
it[Timelines.emojiIds].split(",").mapNotNull { s -> s.toLongOrNull() }
)
}
return statusQueryService.findByPostIdsWithMediaIds(statusQueries)
}
override suspend fun getTimeline( override suspend fun getTimeline(
forUserId: Long?, forUserId: Long?,

View File

@ -8,15 +8,6 @@ import org.springframework.stereotype.Service
@Service @Service
@Suppress("LongParameterList") @Suppress("LongParameterList")
interface GenerateTimelineService { interface GenerateTimelineService {
suspend fun getTimeline(
forUserId: Long? = null,
localOnly: Boolean = false,
mediaOnly: Boolean = false,
maxId: Long? = null,
minId: Long? = null,
sinceId: Long? = null,
limit: Int = 20
): List<Status>
suspend fun getTimeline( suspend fun getTimeline(
forUserId: Long? = null, forUserId: Long? = null,

View File

@ -20,51 +20,6 @@ class MongoGenerateTimelineService(
private val mongoTemplate: MongoTemplate private val mongoTemplate: MongoTemplate
) : ) :
GenerateTimelineService { GenerateTimelineService {
override suspend fun getTimeline(
forUserId: Long?,
localOnly: Boolean,
mediaOnly: Boolean,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int
): List<Status> {
val query = Query()
if (forUserId != null) {
val criteria = Criteria.where("userId").`is`(forUserId)
query.addCriteria(criteria)
}
if (localOnly) {
val criteria = Criteria.where("isLocal").`is`(true)
query.addCriteria(criteria)
}
if (maxId != null) {
val criteria = Criteria.where("postId").lt(maxId)
query.addCriteria(criteria)
}
if (minId != null) {
val criteria = Criteria.where("postId").gt(minId)
query.addCriteria(criteria)
}
query.limit(limit)
query.with(Sort.by(Sort.Direction.DESC, "createdAt"))
val timelines = mongoTemplate.find(query, Timeline::class.java)
return statusQueryService.findByPostIdsWithMediaIds(
timelines.map {
StatusQuery(
it.postId,
it.replyId,
it.repostId,
it.mediaIds,
it.emojiIds
)
}
)
}
override suspend fun getTimeline( override suspend fun getTimeline(
forUserId: Long?, forUserId: Long?,

View File

@ -9,15 +9,6 @@ import org.springframework.stereotype.Service
@Suppress("LongParameterList") @Suppress("LongParameterList")
interface TimelineApiService { interface TimelineApiService {
suspend fun publicTimeline(
localOnly: Boolean = false,
remoteOnly: Boolean = false,
mediaOnly: Boolean = false,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int = 20
): List<Status>
suspend fun publicTimeline( suspend fun publicTimeline(
localOnly: Boolean = false, localOnly: Boolean = false,
@ -26,14 +17,6 @@ interface TimelineApiService {
page: Page page: Page
): PaginationList<Status, Long> ): PaginationList<Status, Long>
suspend fun homeTimeline(
userId: Long,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int = 20
): List<Status>
suspend fun homeTimeline( suspend fun homeTimeline(
userId: Long, userId: Long,
page: Page page: Page
@ -45,49 +28,18 @@ class TimelineApiServiceImpl(
private val generateTimelineService: GenerateTimelineService, private val generateTimelineService: GenerateTimelineService,
private val transaction: Transaction private val transaction: Transaction
) : TimelineApiService { ) : TimelineApiService {
override suspend fun publicTimeline(
localOnly: Boolean,
remoteOnly: Boolean,
mediaOnly: Boolean,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int
): List<Status> = transaction.transaction {
generateTimelineService.getTimeline(
forUserId = 0,
localOnly = localOnly,
mediaOnly = mediaOnly,
maxId = maxId,
minId = minId,
sinceId = sinceId,
limit = limit
)
}
override suspend fun publicTimeline( override suspend fun publicTimeline(
localOnly: Boolean, localOnly: Boolean,
remoteOnly: Boolean, remoteOnly: Boolean,
mediaOnly: Boolean, mediaOnly: Boolean,
page: Page page: Page
): PaginationList<Status, Long> = generateTimelineService.getTimeline(forUserId = 0, localOnly, mediaOnly, page) ): PaginationList<Status, Long> = transaction.transaction {
return@transaction generateTimelineService.getTimeline(forUserId = 0, localOnly, mediaOnly, page)
override suspend fun homeTimeline(
userId: Long,
maxId: Long?,
minId: Long?,
sinceId: Long?,
limit: Int
): List<Status> = transaction.transaction {
generateTimelineService.getTimeline(
forUserId = userId,
maxId = maxId,
minId = minId,
sinceId = sinceId,
limit = limit
)
} }
override suspend fun homeTimeline(userId: Long, page: Page): PaginationList<Status, Long> = override suspend fun homeTimeline(userId: Long, page: Page): PaginationList<Status, Long> =
generateTimelineService.getTimeline(forUserId = userId, page = page) transaction.transaction {
return@transaction generateTimelineService.getTimeline(forUserId = userId, page = page)
}
} }