From 68b10b83111ecdde604d8a979f9060214c840f92 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 27 Aug 2026 13:37:39 +0200 Subject: [PATCH] Fix threshold being recalculated at each addition in the bloom filter --- app/models/account_reach_filter.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/account_reach_filter.rb b/app/models/account_reach_filter.rb index 30fc39dd405..fd60c867f32 100644 --- a/app/models/account_reach_filter.rb +++ b/app/models/account_reach_filter.rb @@ -58,12 +58,15 @@ class AccountReachFilter < ApplicationRecord hosts.each do |host| filter.add("#{salt}:#{host}") + next if filter.set_bits < threshold + # We have reached the threshold after which false-positives are too frequent for us. + # Either update the filter or mark it as saturated. if filter.size < BLOOM_SIZE_FILTER_THRESHOLD - upgrade_filter! if filter.set_bits >= threshold + upgrade_filter! threshold = (TARGET_SATURATION_FALSE_POSITIVE_RATE**(1.0 / filter.k)) * filter.m - elsif filter.set_bits >= threshold + else update!(saturated: true, bloom_filter: nil) break