1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-05 07:20:13 +01:00

Improve banned forgiveness logic

This commit is contained in:
Piero Toffanin 2021-11-24 12:41:12 -05:00
parent cda2d3ed96
commit 3a7527c418

View File

@ -7,10 +7,19 @@ active = False
threshold = -1
def clear_banned():
def forgive_banned():
global banned
banned = {}
clear_list = []
for ip in banned:
if banned[ip] <= 0:
clear_list.append(ip)
else:
banned[ip] -= 1
for ip in clear_list:
del banned[ip]
def setup(violations_threshold=100):
global active
@ -20,7 +29,7 @@ def setup(violations_threshold=100):
threshold = violations_threshold
scheduler = BackgroundScheduler()
scheduler.add_job(func=clear_banned, trigger="interval", weeks=4)
scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5)
scheduler.start()
# Shut down the scheduler when exiting the app