From 051e44c63ad54b03cc5cc1e48855a9890c6c5e07 Mon Sep 17 00:00:00 2001 From: Nick Black Date: Fri, 25 Jan 2008 17:02:43 +0000 Subject: [PATCH 1/1] fixed bug in add version rake task --- lib/tasks/add_version_to_nodes.rake | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/tasks/add_version_to_nodes.rake b/lib/tasks/add_version_to_nodes.rake index 990ce5c4c..5301738c0 100644 --- a/lib/tasks/add_version_to_nodes.rake +++ b/lib/tasks/add_version_to_nodes.rake @@ -1,19 +1,20 @@ namespace 'db' do - desc 'Adds a version number to the noes table' + desc 'Adds a version number to the nodes table' task :node_version do require File.dirname(__FILE__) + '/../../config/environment' - lower_bound = 0 - increment = 100 - node_count = OldNode.count - puts node_count + increment = 1000 + offset = 0 + id_max = OldNode.find(:first, :order => 'id desc').id - while lower_bound < node_count - upper_bound = lower_bound + increment - hash = {} - - OldNode.find(:all, :conditions => ['id >= ? AND id < ?',lower_bound, upper_bound], :order => 'timestamp').each do |node| - hash[node.id] = [] if hash[node.id].nil? + while offset < (id_max + increment) + hash = {} + + #should be offsetting not selecting + OldNode.find(:all, :limit => increment, :offset => offset, :order => 'timestamp').each do |node| + if hash[node.id].nil? + hash[node.id] = [] + end hash[node.id] << node end @@ -33,7 +34,7 @@ namespace 'db' do n +=1 end end - lower_bound += increment + offset += increment end end end -- 2.43.2