mirror of https://github.com/hykilpikonna/AquaDX
[O] Optimize GetUserItemApi loading speed
parent
015fa3dc9f
commit
54e865feb2
|
@ -7,7 +7,6 @@ import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2ItemKind
|
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2ItemKind
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.data.domain.PageRequest
|
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import kotlin.jvm.optionals.getOrNull
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
|
||||||
|
@ -45,11 +44,8 @@ class GetUserItemHandler(
|
||||||
override fun handle(request: Map<String, Any>): Any {
|
override fun handle(request: Map<String, Any>): Any {
|
||||||
val userId = (request["userId"] as Number).toLong()
|
val userId = (request["userId"] as Number).toLong()
|
||||||
val nextIndexVal = (request["nextIndex"] as Number).toLong()
|
val nextIndexVal = (request["nextIndex"] as Number).toLong()
|
||||||
val maxCount = (request["maxCount"] as Number).toInt()
|
|
||||||
|
|
||||||
val kind = (nextIndexVal / MULT).toInt()
|
val kind = (nextIndexVal / MULT).toInt()
|
||||||
val nextIndex = (nextIndexVal % MULT).toInt()
|
|
||||||
val pageNum = nextIndex / maxCount
|
|
||||||
val kindType = Mai2ItemKind.ALL[kind]?.name
|
val kindType = Mai2ItemKind.ALL[kind]?.name
|
||||||
|
|
||||||
// Aqua Net game unlock feature
|
// Aqua Net game unlock feature
|
||||||
|
@ -74,18 +70,8 @@ class GetUserItemHandler(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount))
|
return repos.userItem.findByUserCardExtIdAndItemKind(userId, kind).apply {
|
||||||
|
logger.info("Response: $size $kindType items - DB") }
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -75,6 +75,7 @@ interface Mai2UserGeneralDataRepo : UserLinked<Mai2UserGeneralData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Mai2UserItemRepo : UserLinked<Mai2UserItem> {
|
interface Mai2UserItemRepo : UserLinked<Mai2UserItem> {
|
||||||
|
fun findByUserCardExtIdAndItemKind(userId: Long, kind: Int): List<Mai2UserItem>
|
||||||
fun findByUserAndItemKindAndItemId(user: Mai2UserDetail, itemKind: Int, itemId: Int): Optional<Mai2UserItem>
|
fun findByUserAndItemKindAndItemId(user: Mai2UserDetail, itemKind: Int, itemId: Int): Optional<Mai2UserItem>
|
||||||
|
|
||||||
fun findByUser_Card_ExtIdAndItemKind(userId: Long, kind: Int, page: Pageable): Page<Mai2UserItem>
|
fun findByUser_Card_ExtIdAndItemKind(userId: Long, kind: Int, page: Pageable): Page<Mai2UserItem>
|
||||||
|
|
Loading…
Reference in New Issue