mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Add expiry to redis ratelimiting
This commit is contained in:
parent
6bb6a7ae05
commit
cbe232ca0c
@ -33,7 +33,7 @@ from wtforms_sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
|
||||
from app.logic.LogicError import LogicError
|
||||
from app.logic.packages import do_edit_package
|
||||
from app.querybuilder import QueryBuilder
|
||||
from app.rediscache import has_key, set_key
|
||||
from app.rediscache import has_key, set_temp_key
|
||||
from app.tasks.importtasks import import_repo_screenshot, check_zip_release
|
||||
from app.tasks.webhooktasks import post_discord_webhook
|
||||
from app.logic.game_support import GameSupportResolver
|
||||
@ -65,7 +65,7 @@ def list_all():
|
||||
edited = True
|
||||
key = "tag/{}/{}".format(ip, tag.name)
|
||||
if not has_key(key):
|
||||
set_key(key, "true")
|
||||
set_temp_key(key, "true")
|
||||
Tag.query.filter_by(id=tag.id).update({
|
||||
"views": Tag.views + 1
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ from wtforms_sqlalchemy.fields import QuerySelectField
|
||||
from app.logic.releases import do_create_vcs_release, LogicError, do_create_zip_release
|
||||
from app.models import Package, db, User, PackageState, Permission, UserRank, PackageDailyStats, MinetestRelease, \
|
||||
PackageRelease, PackageUpdateTrigger, PackageUpdateConfig
|
||||
from app.rediscache import has_key, set_key, make_download_key
|
||||
from app.rediscache import has_key, set_temp_key, make_download_key
|
||||
from app.tasks.importtasks import check_update_config
|
||||
from app.utils import is_user_bot, is_package_page, nonempty_or_none
|
||||
from . import bp, get_package_tabs
|
||||
@ -122,7 +122,7 @@ def download_release(package, id):
|
||||
|
||||
key = make_download_key(ip, release.package)
|
||||
if not has_key(key):
|
||||
set_key(key, "true")
|
||||
set_temp_key(key, "true")
|
||||
|
||||
bonus = 0
|
||||
if reason == "new":
|
||||
|
@ -20,12 +20,15 @@ from . import redis_client
|
||||
# and also means that the rest of the code avoids knowing about `app`
|
||||
|
||||
|
||||
EXPIRY_TIME_S = 2*7*24*60*60 # 2 weeks
|
||||
|
||||
|
||||
def make_download_key(ip, package):
|
||||
return "{}/{}/{}".format(ip, package.author.username, package.name)
|
||||
|
||||
|
||||
def set_key(key, v):
|
||||
redis_client.set(key, v)
|
||||
def set_temp_key(key, v):
|
||||
redis_client.set(key, v, ex=EXPIRY_TIME_S)
|
||||
|
||||
|
||||
def has_key(key):
|
||||
|
Loading…
Reference in New Issue
Block a user