From e1bd73342a53bc7fc7e314e91756389d9fae043a Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Tue, 22 Oct 2024 16:55:51 -0300 Subject: [PATCH] Increase daily check range --- .../lorittaautomods/CheckDupeClientIds.kt | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt b/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt index 2ceda82..ebacd2a 100644 --- a/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt +++ b/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt @@ -58,9 +58,9 @@ class CheckDupeClientIds(val helper: LorittaHelper) : RunnableCoroutine { val usersToBeBanned = transaction(helper.databases.lorittaDatabase) { val now = Instant.now() - .minusSeconds(86_400) + .minusSeconds(604_800) // 7 days - val dailiesGotInLast24Hours = Dailies + val dailiesRecentlyRetrievedHours = Dailies .innerJoin(BrowserFingerprints) .innerJoin(Profiles, { Profiles.id }, { Dailies.receivedById }) .selectAll() @@ -69,37 +69,38 @@ class CheckDupeClientIds(val helper: LorittaHelper) : RunnableCoroutine { } .toList() - val clientIds = dailiesGotInLast24Hours.map { it[BrowserFingerprints.clientId] } - - val clientIdsThatAreBanned = Dailies - .innerJoin(BrowserFingerprints) - .innerJoin(BannedUsers, { Dailies.receivedById }, { BannedUsers.userId }) - .selectAll() - .where { - BrowserFingerprints.clientId inList clientIds and (BannedUsers.userId inSubQuery validBannedUsersList(now.toEpochMilli())) - } - .toList() - - val usersToBeBanned = mutableListOf() + val allClientIds = dailiesRecentlyRetrievedHours.map { it[BrowserFingerprints.clientId] } val alreadyChecked = mutableSetOf() + val usersToBeBanned = mutableListOf() - for (user in dailiesGotInLast24Hours) { - if (user[Dailies.receivedById] in alreadyChecked) - continue - - val bannedUsersAssociatedWithThisUser = clientIdsThatAreBanned.filter { it[BrowserFingerprints.clientId] == user[BrowserFingerprints.clientId] } - - if (bannedUsersAssociatedWithThisUser.isNotEmpty()) { - usersToBeBanned.add( - BannedUser( - user[Dailies.receivedById], - bannedUsersAssociatedWithThisUser.map { it[BannedUsers.userId] }.distinct(), - user[BrowserFingerprints.clientId], - bannedUsersAssociatedWithThisUser.minBy { it[BannedUsers.bannedAt] }[BannedUsers.reason], - user[Profiles.money] + allClientIds.chunked(65_535).forEach { clientIds -> + val clientIdsThatAreBanned = Dailies + .innerJoin(BrowserFingerprints) + .innerJoin(BannedUsers, { Dailies.receivedById }, { BannedUsers.userId }) + .selectAll() + .where { + BrowserFingerprints.clientId inList clientIds and (BannedUsers.userId inSubQuery validBannedUsersList(now.toEpochMilli())) + } + .toList() + + for (user in dailiesRecentlyRetrievedHours) { + if (user[Dailies.receivedById] in alreadyChecked) + continue + + val bannedUsersAssociatedWithThisUser = clientIdsThatAreBanned.filter { it[BrowserFingerprints.clientId] == user[BrowserFingerprints.clientId] } + + if (bannedUsersAssociatedWithThisUser.isNotEmpty()) { + usersToBeBanned.add( + BannedUser( + user[Dailies.receivedById], + bannedUsersAssociatedWithThisUser.map { it[BannedUsers.userId] }.distinct(), + user[BrowserFingerprints.clientId], + bannedUsersAssociatedWithThisUser.minBy { it[BannedUsers.bannedAt] }[BannedUsers.reason], + user[Profiles.money] + ) ) - ) - alreadyChecked.add(user[Dailies.receivedById]) + alreadyChecked.add(user[Dailies.receivedById]) + } } }