Tweaked import:users logic

This commit is contained in:
nise.moe 2024-03-02 18:16:58 +01:00
parent 9cea7e66a4
commit 5794b5a2fb

View File

@ -27,7 +27,7 @@ class ImportUsers(
companion object { companion object {
const val SLEEP_AFTER_API_CALL = 1000L const val SLEEP_AFTER_API_CALL = 3000L
} }
@ -53,7 +53,7 @@ class ImportUsers(
private fun updateUsers() { private fun updateUsers() {
// Fetch 50 users with the oldest last update time // Fetch 50 users with the oldest last update time
// We exclude all users with at least 1 banned score in the last 3 months
val threeMonthsAgo = LocalDateTime.now().minusMonths(3) val threeMonthsAgo = LocalDateTime.now().minusMonths(3)
val bannedUsersCondition = SCORES.IS_BANNED.eq(true) val bannedUsersCondition = SCORES.IS_BANNED.eq(true)
@ -62,8 +62,7 @@ class ImportUsers(
val userIds = dslContext val userIds = dslContext
.select(USERS.USER_ID) .select(USERS.USER_ID)
.from(USERS) .from(USERS)
.leftJoin(SCORES).on(USERS.USER_ID.eq(SCORES.USER_ID).and(bannedUsersCondition)) .leftJoin(SCORES).on(USERS.USER_ID.eq(SCORES.USER_ID))
.where(SCORES.USER_ID.isNull)
.orderBy(USERS.SYS_LAST_UPDATE.asc()) .orderBy(USERS.SYS_LAST_UPDATE.asc())
.limit(50) .limit(50)
.fetchInto(Long::class.java) .fetchInto(Long::class.java)
@ -78,6 +77,11 @@ class ImportUsers(
// Check which ids are missing; if any are missing, we explicitly check if they're banned. // 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 } } val missingIds = userIds.filter { it !in usersResult.users.map { it.id } }
for (missingId in missingIds) { for (missingId in missingIds) {
// 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))) {
continue
}
val isUserBanned = this.osuApi.checkIfUserBanned(missingId) val isUserBanned = this.osuApi.checkIfUserBanned(missingId)
Thread.sleep(SLEEP_AFTER_API_CALL) Thread.sleep(SLEEP_AFTER_API_CALL)
if (isUserBanned == true) { if (isUserBanned == true) {