[O] Optimize GetUserItemApi loading speed

pull/23/head
Azalea 2024-03-23 07:19:58 -04:00
parent 015fa3dc9f
commit 54e865feb2
2 changed files with 3 additions and 16 deletions

View File

@ -7,7 +7,6 @@ import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2ItemKind
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.stereotype.Component
import kotlin.jvm.optionals.getOrNull
@ -45,11 +44,8 @@ class GetUserItemHandler(
override fun handle(request: Map<String, Any>): Any {
val userId = (request["userId"] as Number).toLong()
val nextIndexVal = (request["nextIndex"] as Number).toLong()
val maxCount = (request["maxCount"] as Number).toInt()
val kind = (nextIndexVal / MULT).toInt()
val nextIndex = (nextIndexVal % MULT).toInt()
val pageNum = nextIndex / maxCount
val kindType = Mai2ItemKind.ALL[kind]?.name
// Aqua Net game unlock feature
@ -74,18 +70,8 @@ class GetUserItemHandler(
)
}
val dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount))
val currentIndex = kind * MULT + maxCount * pageNum + dbPage.numberOfElements
val result = mapOf(
"userId" to userId,
"nextIndex" to if (dbPage.numberOfElements < maxCount) 0 else currentIndex,
"itemKind" to kind,
"userItemList" to dbPage.content
)
logger.info("Response: ${dbPage.numberOfElements} $kindType items")
return result
return repos.userItem.findByUserCardExtIdAndItemKind(userId, kind).apply {
logger.info("Response: $size $kindType items - DB") }
}
companion object {

View File

@ -75,6 +75,7 @@ interface Mai2UserGeneralDataRepo : UserLinked<Mai2UserGeneralData> {
}
interface Mai2UserItemRepo : UserLinked<Mai2UserItem> {
fun findByUserCardExtIdAndItemKind(userId: Long, kind: Int): List<Mai2UserItem>
fun findByUserAndItemKindAndItemId(user: Mai2UserDetail, itemKind: Int, itemId: Int): Optional<Mai2UserItem>
fun findByUser_Card_ExtIdAndItemKind(userId: Long, kind: Int, page: Pageable): Page<Mai2UserItem>