poprawki
This commit is contained in:
24
app.py
24
app.py
@@ -280,11 +280,29 @@ def track_url_request(url):
|
|||||||
|
|
||||||
def add_recent_link(url, target_ip):
|
def add_recent_link(url, target_ip):
|
||||||
ts = datetime.now().isoformat()
|
ts = datetime.now().isoformat()
|
||||||
link_data = f"{ts}|{url}|{target_ip}"
|
new_item = f"{ts}|{url}|{target_ip}"
|
||||||
|
key = "recent_links"
|
||||||
|
|
||||||
|
current = redis_client.lrange(key, 0, -1)
|
||||||
|
filtered = []
|
||||||
|
for raw in current:
|
||||||
|
try:
|
||||||
|
s = raw.decode()
|
||||||
|
parts = s.split("|")
|
||||||
|
if len(parts) >= 3 and parts[1] == url and parts[2] == target_ip:
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
filtered.append(raw)
|
||||||
|
|
||||||
with redis_client.pipeline() as pipe:
|
with redis_client.pipeline() as pipe:
|
||||||
pipe.lpush("recent_links", link_data)
|
pipe.delete(key)
|
||||||
pipe.ltrim("recent_links", 0, 9)
|
pipe.lpush(key, new_item)
|
||||||
|
if filtered:
|
||||||
|
pipe.rpush(key, *filtered[:99])
|
||||||
|
pipe.ltrim(key, 0, 9)
|
||||||
pipe.execute()
|
pipe.execute()
|
||||||
|
|
||||||
redis_client.incr("stats:recent_links_added")
|
redis_client.incr("stats:recent_links_added")
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user