From 6196f7ba67614074af7f49f889d8d331d9d07fe9 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 10 Dec 2019 00:49:24 -0600 Subject: [PATCH] BURs: fix exception when estimating post counts of category changes. Fix an error in operator precedence: > sum + Tag.find_by_name(token[1]).try(:post_count) || 0 This was treated as `(sum + X) || 0` not `sum + (X || 0)` as intended. This failed when X was nil. --- app/logical/alias_and_implication_importer.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index 4a8fb3f99..7290f895d 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -80,24 +80,20 @@ class AliasAndImplicationImporter def estimate_update_count tokens = self.class.tokenize(text) - tokens.inject(0) do |sum, token| + tokens.map do |token| case token[0] when :create_alias - sum + TagAlias.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count - + TagAlias.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count when :create_implication - sum + TagImplication.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count - + TagImplication.new(antecedent_name: token[1], consequent_name: token[2]).estimate_update_count when :mass_update - sum + TagBatchChangeJob.estimate_update_count(token[1], token[2]) - + TagBatchChangeJob.estimate_update_count(token[1], token[2]) when :change_category - sum + Tag.find_by_name(token[1]).try(:post_count) || 0 - + Tag.find_by_name(token[1]).try(:post_count) || 0 else - sum + 0 + 0 end - end + end.sum end def affected_tags