From 18dfbd16eadddec1d33e46ea9f99a4e08e0fc5f6 Mon Sep 17 00:00:00 2001 From: drusepth Date: Fri, 1 Apr 2022 21:29:52 -0700 Subject: [PATCH] add lenience on storage integrity update --- lib/tasks/data_integrity.rake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tasks/data_integrity.rake b/lib/tasks/data_integrity.rake index de5de7a3..d3a98106 100644 --- a/lib/tasks/data_integrity.rake +++ b/lib/tasks/data_integrity.rake @@ -135,10 +135,16 @@ namespace :data_integrity do old_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil + # For the sake of minimizing db updates while blazing through all users, + # we ignore a small amount (1kb) of difference between saved bandwidth + # and calculated bandwidth. Users should never be more than 1kb off though. + byte_lenience = 1000 + User.find_each do |user| correct_bandwidth = SubscriptionService.recalculate_bandwidth_for(user) - if user.upload_bandwidth_kb != correct_bandwidth + difference = (user.upload_bandwidth_kb - correct_bandwidth).abs + if difference > byte_lenience puts "Correcting user #{user.id} bandwidth: #{user.upload_bandwidth_kb} --> #{correct_bandwidth}" # user.update(upload_bandwidth_kb: correct_bandwidth) end