From ee44c1227cf6418b42e06f6559ef771481037cb6 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Sun, 15 Oct 2017 21:56:41 -0400 Subject: [PATCH] better bulk uploading --- app/models/attempt.rb | 5 +---- app/models/recipient.rb | 7 +++++++ lib/tasks/data.rake | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/attempt.rb b/app/models/attempt.rb index ab3099a9..b5019afe 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -79,10 +79,7 @@ class Attempt < ApplicationRecord def update_counts return if ENV['BULK_PROCESS'] - recipient.update_attributes( - attempts_count: recipient.attempts.count, - responses_count: recipient.attempts.with_answer.count - ) + recipient.update_counts end end diff --git a/app/models/recipient.rb b/app/models/recipient.rb index dd39040a..2c430b8d 100644 --- a/app/models/recipient.rb +++ b/app/models/recipient.rb @@ -29,6 +29,13 @@ class Recipient < ApplicationRecord end end + def update_counts + update_attributes( + attempts_count: attempts.count, + responses_count: attempts.with_answer.count + ) + end + private def sync_lists diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 63a3aff0..0eeda213 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -254,5 +254,6 @@ namespace :data do ENV.delete('BULK_PROCESS') SchoolCategory.all.each { |sc| sc.sync_aggregated_responses } + Recipient.all.each { |r| r.update_counts } end end