-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 添加延迟刷新排名列表 - 移动 graphql 相关类文件
- Loading branch information
Showing
56 changed files
with
302 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/kotlin/graphql/DataFetchException.kt → ...de2/booster/graphql/DataFetchException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package graphql | ||
package explode2.booster.graphql | ||
|
||
import org.jetbrains.annotations.Contract | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...main/kotlin/graphql/DefinitionConverts.kt → ...de2/booster/graphql/DefinitionConverts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
booster/src/main/kotlin/explode2/booster/graphql/GraphqlDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package explode2.booster.graphql | ||
|
||
import explode2.labyrinth.* | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
object GraphqlDataSource : KoinComponent { | ||
|
||
internal val assInfoRepo by inject<AssessmentInfoRepository>() | ||
internal val assRecRepo by inject<AssessmentRecordRepository>() | ||
internal val recRepo by inject<GameRecordRepository>() | ||
internal val songRepo by inject<SongSetRepository>() | ||
internal val userRepo by inject<GameUserRepository>() | ||
internal val chartRepo by inject<SongChartRepository>() | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...r/src/main/kotlin/graphql/MazeProvider.kt → .../explode2/booster/graphql/MazeProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/main/kotlin/graphql/NonNegativeInt.kt → ...xplode2/booster/graphql/NonNegativeInt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package graphql | ||
package explode2.booster.graphql | ||
|
||
@JvmInline | ||
value class NonNegativeInt(val value: Int) { | ||
|
70 changes: 70 additions & 0 deletions
70
booster/src/main/kotlin/explode2/booster/graphql/RefreshingRankingList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package explode2.booster.graphql | ||
|
||
import explode2.booster.graphql.definition.PlayRecordWithRankModel | ||
import explode2.gateau.GameRecord | ||
import explode2.labyrinth.GameRecordRepository | ||
import java.time.LocalDateTime | ||
import kotlin.time.Duration.Companion.hours | ||
import kotlin.time.toJavaDuration | ||
|
||
data class RefreshingRankingList( | ||
val chartId: String, | ||
val expireHours: Int, | ||
val repo: GameRecordRepository | ||
) { | ||
|
||
private var cache: List<PlayRecordWithRankModel>? = null | ||
private var lastUpdateTime: LocalDateTime? = null | ||
|
||
fun clear() { | ||
cache = null | ||
lastUpdateTime = null | ||
} | ||
|
||
private fun update() { | ||
cache = repo.getChartRecords(chartId, 100, 0).map(GameRecord::tunerize) | ||
lastUpdateTime = LocalDateTime.now() | ||
} | ||
|
||
fun get(): List<PlayRecordWithRankModel> { | ||
val lastUpdateTime = lastUpdateTime | ||
if( | ||
lastUpdateTime == null || | ||
lastUpdateTime + 24.hours.toJavaDuration() <= LocalDateTime.now() || | ||
cache == null | ||
) { | ||
update() | ||
} | ||
|
||
return cache!! | ||
} | ||
|
||
fun get(limit: Int, skip: Int): List<PlayRecordWithRankModel> { | ||
require(limit > 0) | ||
require(skip >= 0) | ||
return get().drop(skip).take(limit) | ||
} | ||
|
||
fun get(playerId: String): PlayRecordWithRankModel? { | ||
val lastUpdateTime = lastUpdateTime | ||
if( | ||
lastUpdateTime == null || | ||
lastUpdateTime + 24.hours.toJavaDuration() <= LocalDateTime.now() || | ||
cache == null | ||
) { | ||
update() | ||
} | ||
|
||
return cache!!.firstOrNull { it.player._id == playerId } | ||
} | ||
|
||
companion object { | ||
|
||
private val instances = mutableMapOf<String, RefreshingRankingList>() | ||
|
||
fun getOrCreate(chartId: String, expireHours: Int, repo: GameRecordRepository): RefreshingRankingList { | ||
return instances.getOrPut(chartId) { RefreshingRankingList(chartId, expireHours, repo) } | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...raphql/definition/AfterAssessmentModel.kt → ...raphql/definition/AfterAssessmentModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...raphql/definition/AfterPlaySubmitModel.kt → ...raphql/definition/AfterPlaySubmitModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...raphql/definition/AssessmentChartModel.kt → ...raphql/definition/AssessmentChartModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...raphql/definition/AssessmentGroupModel.kt → ...raphql/definition/AssessmentGroupModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lin/graphql/definition/AssessmentModel.kt → ...ter/graphql/definition/AssessmentModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/definition/AssessmentPlayRecordModel.kt → ...l/definition/AssessmentPlayRecordModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...finition/AssessmentRecordWithRankModel.kt → ...finition/AssessmentRecordWithRankModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package graphql.definition | ||
package explode2.booster.graphql.definition | ||
|
||
import java.time.OffsetDateTime | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...phql/definition/AssessmentRecordsModel.kt → ...phql/definition/AssessmentRecordsModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 6 additions & 10 deletions
16
...n/graphql/definition/BasicReviewerImpl.kt → ...r/graphql/definition/BasicReviewerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.