From 2e78ef4d2281a7f8da9fbfffa67c5c3d088100c3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 1 Apr 2021 17:13:55 +0100 Subject: [PATCH] Smear --- synapse/util/caches/lrucache.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py index 3639cba2da..4db6dd2254 100644 --- a/synapse/util/caches/lrucache.py +++ b/synapse/util/caches/lrucache.py @@ -88,7 +88,7 @@ class _Node: self.prev_node = prev_node self.next_node = next_node - self.allocated_ts = int(reactor.seconds()) + random.randint(-30, 30) + self.allocated_ts = int(reactor.seconds()) + random.randint(-60, 60) class LruCache(Generic[KT, VT]): @@ -178,9 +178,12 @@ class LruCache(Generic[KT, VT]): ten_minutes_ago = int(reactor.seconds()) - 10 * 60 while i < 100 and ( cache_len() > self.max_size - or 0 < list_root.prev_node.allocated_ts < ten_minutes_ago + or list_root.prev_node.allocated_ts < ten_minutes_ago + 60 ): i += 1 + if list_root.prev_node.allocated_ts > ten_minutes_ago: + continue + todelete = list_root.prev_node if list_root == todelete: break