Updated users checkers

This commit is contained in:
nise.moe 2024-03-05 13:01:19 +01:00
parent 38be6161a3
commit edbe412f14
2 changed files with 37 additions and 11 deletions

View File

@ -274,6 +274,8 @@ class ImportScores(
.groupBy(SCORES.USER_ID)
.fetchInto(Long::class.java)
this.logger.info("Found ${suspiciousScores.size} suspicious scores to update.")
val stolenReplays = dslContext
.select(ScoreService.osuScoreAlias1.USER_ID, ScoreService.osuScoreAlias2.USER_ID)
.from(SCORES_SIMILARITY)
@ -296,13 +298,15 @@ class ImportScores(
)
} + stolenReplays.map { it.get(ScoreService.osuScoreAlias2.USER_ID, Long::class.java) }).distinct()
for(userId in suspiciousUserIds) {
suspiciousUserIds.forEachIndexed { index, userId ->
this.logger.info("Checking user $userId [$index/${suspiciousUserIds.size}]")
val isBanned = this.osuApi.checkIfUserBanned(userId)
if(isBanned == true) {
dslContext.update(SCORES)
.set(SCORES.IS_BANNED, true)
.where(SCORES.USER_ID.eq(userId))
.execute()
this.logger.info("User $userId is banned.")
}
Thread.sleep(SLEEP_AFTER_API_CALL)
}

View File

@ -6,6 +6,7 @@ import com.nisemoe.nise.database.UserService
import com.nisemoe.nise.integrations.DiscordEmbed
import com.nisemoe.nise.integrations.DiscordService
import com.nisemoe.nise.osu.OsuApi
import org.jooq.Condition
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
@ -13,6 +14,7 @@ import org.springframework.context.annotation.Profile
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.time.OffsetDateTime
@Service
@Profile("import:users")
@ -52,21 +54,36 @@ class ImportUsers(
}
private fun updateUsers() {
// Fetch 50 users with the oldest last update time
val pageSize = 50
var currentPage = 0
do {
val offset = currentPage * pageSize
val userIds = dslContext
.select(USERS.USER_ID)
.from(USERS)
.leftJoin(SCORES).on(USERS.USER_ID.eq(SCORES.USER_ID))
.orderBy(USERS.SYS_LAST_UPDATE.asc())
.limit(pageSize)
.offset(offset)
.fetchInto(Long::class.java)
// Process the fetched users
if (userIds.isNotEmpty()) {
updateUserIds(userIds)
}
currentPage++
} while (userIds.size == pageSize)
}
private fun updateUserIds(userIds: List<Long>) {
val threeMonthsAgo = LocalDateTime.now().minusMonths(3)
val bannedUsersCondition = SCORES.IS_BANNED.eq(true)
.and(SCORES.DATE.greaterOrEqual(threeMonthsAgo))
val userIds = dslContext
.select(USERS.USER_ID)
.from(USERS)
.leftJoin(SCORES).on(USERS.USER_ID.eq(SCORES.USER_ID))
.orderBy(USERS.SYS_LAST_UPDATE.asc())
.limit(50)
.fetchInto(Long::class.java)
val usersResult = this.osuApi.getUsersBatch(userIds)
if (usersResult == null) {
@ -77,8 +94,13 @@ class ImportUsers(
// Check which ids are missing; if any are missing, we explicitly check if they're banned.
val missingIds = userIds.filter { it !in usersResult.users.map { it.id } }
for (missingId in missingIds) {
dslContext.update(USERS)
.set(USERS.SYS_LAST_UPDATE, OffsetDateTime.now())
.where(USERS.USER_ID.eq(missingId))
.execute()
// We exclude all users with at least 1 banned score in the last 3 months
if(dslContext.fetchExists(SCORES, SCORES.USER_ID.eq(missingId).and(bannedUsersCondition))) {
if (dslContext.fetchExists(SCORES, SCORES.USER_ID.eq(missingId).and(bannedUsersCondition))) {
continue
}