From 259d716e0f77c377d31d6c0373c77e9e191b6591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 29 Aug 2025 22:36:41 +0200 Subject: [PATCH] poprawki --- app.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 4719ed8..c0cd875 100644 --- a/app.py +++ b/app.py @@ -280,11 +280,29 @@ def track_url_request(url): def add_recent_link(url, target_ip): 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: - pipe.lpush("recent_links", link_data) - pipe.ltrim("recent_links", 0, 9) + pipe.delete(key) + pipe.lpush(key, new_item) + if filtered: + pipe.rpush(key, *filtered[:99]) + pipe.ltrim(key, 0, 9) pipe.execute() + redis_client.incr("stats:recent_links_added")