Fixed batch user statistics, only update replay pairs if new scores have been added to the beatmap

This commit is contained in:
nise.moe 2024-02-22 17:31:03 +01:00
parent 14a2608f2a
commit 051b6384fb
3 changed files with 41 additions and 24 deletions

View File

@ -77,27 +77,29 @@ class UserService(
fun insertApiUser(apiUser: OsuApiModels.UserExtended) { fun insertApiUser(apiUser: OsuApiModels.UserExtended) {
this.logger.debug("Saving user ${apiUser.username}") this.logger.debug("Saving user ${apiUser.username}")
val userStatistics = apiUser.getStatistics()
if(dslContext.fetchExists(USERS, USERS.USER_ID.eq(apiUser.id))) { if(dslContext.fetchExists(USERS, USERS.USER_ID.eq(apiUser.id))) {
dslContext.update(USERS) dslContext.update(USERS)
.set(USERS.USERNAME, apiUser.username) .set(USERS.USERNAME, apiUser.username)
.set(USERS.RANK, apiUser.statistics?.global_rank) .set(USERS.RANK, userStatistics?.global_rank)
.set(USERS.PP_RAW, apiUser.statistics?.pp) .set(USERS.PP_RAW, userStatistics?.pp)
.set(USERS.ACCURACY, apiUser.statistics?.hit_accuracy) .set(USERS.ACCURACY, userStatistics?.hit_accuracy)
.set(USERS.TOTAL_SCORE, apiUser.statistics?.total_score) .set(USERS.TOTAL_SCORE, userStatistics?.total_score)
.set(USERS.RANKED_SCORE, apiUser.statistics?.ranked_score) .set(USERS.RANKED_SCORE, userStatistics?.ranked_score)
.set(USERS.COUNT_300, apiUser.statistics?.count_300) .set(USERS.COUNT_300, userStatistics?.count_300)
.set(USERS.COUNT_100, apiUser.statistics?.count_100) .set(USERS.COUNT_100, userStatistics?.count_100)
.set(USERS.COUNT_50, apiUser.statistics?.count_50) .set(USERS.COUNT_50, userStatistics?.count_50)
.apply { .apply {
if(apiUser.join_date != null) { if(apiUser.join_date != null) {
set(USERS.JOIN_DATE, OffsetDateTime.parse(apiUser.join_date).toLocalDateTime()) set(USERS.JOIN_DATE, OffsetDateTime.parse(apiUser.join_date).toLocalDateTime())
} }
} }
.set(USERS.SECONDS_PLAYED, apiUser.statistics?.play_time) .set(USERS.SECONDS_PLAYED, userStatistics?.play_time)
.set(USERS.COUNTRY, apiUser.country?.code) .set(USERS.COUNTRY, apiUser.country?.code)
.set(USERS.COUNTRY_RANK, apiUser.statistics?.country_rank) .set(USERS.COUNTRY_RANK, userStatistics?.country_rank)
.set(USERS.PLAYCOUNT, apiUser.statistics?.play_count) .set(USERS.PLAYCOUNT, userStatistics?.play_count)
.set(USERS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC)) .set(USERS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC))
.where(USERS.USER_ID.eq(apiUser.id)) .where(USERS.USER_ID.eq(apiUser.id))
.execute() .execute()
@ -108,23 +110,23 @@ class UserService(
val affectedRows = dslContext.insertInto(USERS) val affectedRows = dslContext.insertInto(USERS)
.set(USERS.USER_ID, apiUser.id) .set(USERS.USER_ID, apiUser.id)
.set(USERS.USERNAME, apiUser.username) .set(USERS.USERNAME, apiUser.username)
.set(USERS.RANK, apiUser.statistics?.global_rank) .set(USERS.RANK, userStatistics?.global_rank)
.set(USERS.PP_RAW, apiUser.statistics?.pp) .set(USERS.PP_RAW, userStatistics?.pp)
.set(USERS.ACCURACY, apiUser.statistics?.hit_accuracy) .set(USERS.ACCURACY, userStatistics?.hit_accuracy)
.set(USERS.TOTAL_SCORE, apiUser.statistics?.total_score) .set(USERS.TOTAL_SCORE, userStatistics?.total_score)
.set(USERS.RANKED_SCORE, apiUser.statistics?.ranked_score) .set(USERS.RANKED_SCORE, userStatistics?.ranked_score)
.set(USERS.COUNT_300, apiUser.statistics?.count_300) .set(USERS.COUNT_300, userStatistics?.count_300)
.set(USERS.COUNT_100, apiUser.statistics?.count_100) .set(USERS.COUNT_100, userStatistics?.count_100)
.set(USERS.COUNT_50, apiUser.statistics?.count_50) .set(USERS.COUNT_50, userStatistics?.count_50)
.apply { .apply {
if(apiUser.join_date != null) { if(apiUser.join_date != null) {
set(USERS.JOIN_DATE, OffsetDateTime.parse(apiUser.join_date).toLocalDateTime()) set(USERS.JOIN_DATE, OffsetDateTime.parse(apiUser.join_date).toLocalDateTime())
} }
} }
.set(USERS.SECONDS_PLAYED, apiUser.statistics?.play_time) .set(USERS.SECONDS_PLAYED, userStatistics?.play_time)
.set(USERS.COUNTRY, apiUser.country?.code) .set(USERS.COUNTRY, apiUser.country?.code)
.set(USERS.COUNTRY_RANK, apiUser.statistics?.country_rank) .set(USERS.COUNTRY_RANK, userStatistics?.country_rank)
.set(USERS.PLAYCOUNT, apiUser.statistics?.play_count) .set(USERS.PLAYCOUNT, userStatistics?.play_count)
.set(USERS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC)) .set(USERS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC))
.onDuplicateKeyIgnore() .onDuplicateKeyIgnore()
.execute() .execute()

View File

@ -11,6 +11,11 @@ class OsuApiModels {
val name: String val name: String
) )
@Serializable
data class UserStatisticsRuleset(
val osu: UserStatistics?
)
@Serializable @Serializable
data class UserStatistics( data class UserStatistics(
val count_100: Long, val count_100: Long,
@ -39,9 +44,16 @@ class OsuApiModels {
val join_date: String?, val join_date: String?,
val statistics: UserStatistics?, val statistics: UserStatistics?,
val statistics_rulesets: UserStatisticsRuleset?,
val country: UserCountry? val country: UserCountry?
) ) {
fun getStatistics(): UserStatistics? {
return this.statistics ?: this.statistics_rulesets?.osu
}
}
@Serializable @Serializable
data class UserBatchResponse( data class UserBatchResponse(

View File

@ -357,6 +357,7 @@ class ImportScores(
} }
this.statistics.totalScores = beatmapScores.scores.size this.statistics.totalScores = beatmapScores.scores.size
var totalScoresForBeatmap = 0
for (score in beatmapScores.scores) { for (score in beatmapScores.scores) {
this.statistics.currentScore++ this.statistics.currentScore++
@ -392,10 +393,12 @@ class ImportScores(
continue continue
} }
totalScoresForBeatmap += 1
this.updateScoreWeaving(beatmap, score) this.updateScoreWeaving(beatmap, score)
} }
checkReplaySimilarity(beatmap.id) if(totalScoresForBeatmap > 0)
checkReplaySimilarity(beatmap.id)
dslContext.update(BEATMAPS) dslContext.update(BEATMAPS)
.set(BEATMAPS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC)) .set(BEATMAPS.SYS_LAST_UPDATE, OffsetDateTime.now(ZoneOffset.UTC))