Add a wrapper for get_user_ips

cache-user-ips-for-tracker
Kevin Chung 2020-04-29 22:34:33 -04:00
parent 817b67d1b0
commit 541d7e9cfa
2 changed files with 10 additions and 2 deletions

View File

@ -43,7 +43,7 @@ from CTFd.utils.user import (
get_current_team,
get_current_user,
get_ip,
get_user_ips,
get_current_user_ips,
is_admin,
)
@ -177,7 +177,7 @@ def init_request_processors(app):
return
if authed():
user_ips = get_user_ips(user_id=session["id"])
user_ips = get_current_user_ips()
ip = get_ip()
if ip not in user_ips:
visit = Tracking(ip=get_ip(), user_id=session["id"])

View File

@ -81,6 +81,14 @@ def get_ip(req=None):
return remote_addr
def get_current_user_ips():
if authed():
return get_user_ips(user_id=session["id"])
else:
return None
@cache.memoize
def get_user_ips(user_id):
addrs = (
Tracking.query.with_entities(Tracking.ip.distinct())