diff options
| author | Alban Peignier | 2018-05-29 14:34:59 +0200 |
|---|---|---|
| committer | Johan Van Ryseghem | 2018-05-31 13:58:05 +0200 |
| commit | 40e3cd0fb14650247ea5422b162f91fd4decc4b1 (patch) | |
| tree | 0d6eedecbcdf83ae272caac82996bef7c9fe5d22 /lib | |
| parent | ace3af7f5f3c413582b412e1f54356971107daa6 (diff) | |
| download | chouette-core-40e3cd0fb14650247ea5422b162f91fd4decc4b1.tar.bz2 | |
Use cache and transaction in update_checksums_for_referential. Take Referential id (instead of opaque slug) in command line. Refs #7216
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tasks/referential.rake | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/tasks/referential.rake b/lib/tasks/referential.rake index b3202035b..2e1683208 100644 --- a/lib/tasks/referential.rake +++ b/lib/tasks/referential.rake @@ -82,30 +82,36 @@ namespace :referential do print "⎯"*(80-head.size) print " " count = klass.count - klass.find_each do |o| - o.update_checksum! - if j%10 == 0 - out = "#{"\b"*prev_size}\e[33m#{thing[i]}\e[0m (#{j}/#{count})" - prev_size = out.size - prev_size - 9 - print out - i = (i+1) % thing.size + klass.cache do + klass.find_in_batches(batch_size: 500) do |batch| + klass.transaction do + batch.each do |o| + o.update_checksum! + if j%10 == 0 + out = "#{"\b"*prev_size}\e[33m#{thing[i]}\e[0m (#{j}/#{count})" + prev_size = out.size - prev_size - 9 + print out + i = (i+1) % thing.size + end + j += 1 + end + end end - j += 1 end + print "#{"\b"*prev_size}\e[32m✓\e[0m (#{count}/#{count})\n" end end end desc 'Update all the checksums in the given referential' - task :update_checksums_in_referential, [:slug] => :environment do |t, args| - referential = Referential.find_by_slug(args[:slug]) + task :update_checksums_in_referential, [:id] => :environment do |t, args| + referential = Referential.find(args[:id]) update_checksums_for_referential referential end desc 'Update all the checksums in the given organisation' task :update_checksums_in_organisation, [:organisation_id] => :environment do |t, args| - thing = %w(\\ | / —) Organisation.find(args[:organisation_id]).referentials.find_each do |referential| update_checksums_for_referential referential end |
