Compare commits
2 Commits
e28d3e7211
...
5d44d76671
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d44d76671 | ||
|
|
073966745e |
@ -0,0 +1,46 @@
|
|||||||
|
package com.nisemoe.nise.database
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import javax.sql.DataSource
|
||||||
|
|
||||||
|
data class ReplayCacheReplay(
|
||||||
|
val replayId: Long,
|
||||||
|
val mapId: Int,
|
||||||
|
val userId: Int,
|
||||||
|
val replayData: ByteArray,
|
||||||
|
val mods: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class ReplayCacheService(
|
||||||
|
@Qualifier("replayCacheDataSource") private val dataSource: DataSource,
|
||||||
|
) {
|
||||||
|
fun getReplayById(replayId: Long): ByteArray? =
|
||||||
|
dataSource.connection.use { connection ->
|
||||||
|
val statement = connection.prepareStatement("SELECT replay_data FROM replays WHERE replay_id = ?")
|
||||||
|
statement.setLong(1, replayId)
|
||||||
|
val resultSet = statement.executeQuery()
|
||||||
|
|
||||||
|
var replayData: ByteArray? = null
|
||||||
|
while (resultSet.next()) {
|
||||||
|
replayData = resultSet.getBytes(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return replayData
|
||||||
|
}
|
||||||
|
|
||||||
|
fun insertReplay(replay: ReplayCacheReplay): Boolean =
|
||||||
|
dataSource.connection.use { connection ->
|
||||||
|
val statement = connection.prepareStatement("INSERT INTO replays VALUES (?, ?, ?, ?, ?)")
|
||||||
|
statement.setLong(1, replay.replayId)
|
||||||
|
statement.setInt(2, replay.mapId)
|
||||||
|
statement.setInt(3, replay.userId)
|
||||||
|
statement.setBytes(4, replay.replayData)
|
||||||
|
statement.setInt(5, replay.mods)
|
||||||
|
|
||||||
|
val updateCount = statement.executeUpdate()
|
||||||
|
|
||||||
|
return updateCount != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,8 @@ package com.nisemoe.nise.scheduler
|
|||||||
import com.nisemoe.generated.tables.records.ScoresRecord
|
import com.nisemoe.generated.tables.records.ScoresRecord
|
||||||
import com.nisemoe.generated.tables.references.*
|
import com.nisemoe.generated.tables.references.*
|
||||||
import com.nisemoe.nise.UserQueueDetails
|
import com.nisemoe.nise.UserQueueDetails
|
||||||
|
import com.nisemoe.nise.database.ReplayCacheReplay
|
||||||
|
import com.nisemoe.nise.database.ReplayCacheService
|
||||||
import com.nisemoe.nise.database.ScoreService
|
import com.nisemoe.nise.database.ScoreService
|
||||||
import com.nisemoe.nise.database.UserService
|
import com.nisemoe.nise.database.UserService
|
||||||
import com.nisemoe.nise.integrations.CircleguardService
|
import com.nisemoe.nise.integrations.CircleguardService
|
||||||
@ -36,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController
|
|||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
|
import java.util.Base64
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RestController
|
@RestController
|
||||||
@ -49,7 +52,8 @@ class ImportScores(
|
|||||||
private val scoreService: ScoreService,
|
private val scoreService: ScoreService,
|
||||||
private val updateUserQueueService: UpdateUserQueueService,
|
private val updateUserQueueService: UpdateUserQueueService,
|
||||||
private val circleguardService: CircleguardService,
|
private val circleguardService: CircleguardService,
|
||||||
private val messagingTemplate: SimpMessagingTemplate
|
private val messagingTemplate: SimpMessagingTemplate,
|
||||||
|
private val replayCacheService: ReplayCacheService,
|
||||||
) : InitializingBean {
|
) : InitializingBean {
|
||||||
|
|
||||||
private val userToUpdateBucket = mutableListOf<Long>()
|
private val userToUpdateBucket = mutableListOf<Long>()
|
||||||
@ -784,6 +788,22 @@ class ImportScores(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert into replay cache
|
||||||
|
val replayCacheReplay = ReplayCacheReplay(
|
||||||
|
score.best_id,
|
||||||
|
beatmapId,
|
||||||
|
score.user_id.toInt(),
|
||||||
|
Base64.getDecoder().decode(scoreReplay.content),
|
||||||
|
Mod.combineModStrings(score.mods),
|
||||||
|
)
|
||||||
|
val replayCacheInsertSuccess = replayCacheService.insertReplay(replayCacheReplay)
|
||||||
|
|
||||||
|
if (replayCacheInsertSuccess) {
|
||||||
|
logger.info("Inserted replay ${score.id} into replay cache")
|
||||||
|
} else {
|
||||||
|
logger.error("Could not insert replay ${score.id} into replay cache")
|
||||||
|
}
|
||||||
|
|
||||||
this.statistics.scoresWithReplayAndAnalyzed++
|
this.statistics.scoresWithReplayAndAnalyzed++
|
||||||
|
|
||||||
if (scoreId == null) {
|
if (scoreId == null) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user