mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 15:58:50 +01:00
store rendered notes of todos in database to avoid costly rendering when you load a page
This commit is contained in:
parent
f32e5b256b
commit
bb8b5a4c72
6 changed files with 81 additions and 27 deletions
26
db/migrate/20120412072508_add_rendered_notes.rb
Normal file
26
db/migrate/20120412072508_add_rendered_notes.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class AddRenderedNotes < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :todos, 'rendered_notes', :text
|
||||
|
||||
puts "-- Clearing show_from dates from completed todos"
|
||||
# clear up completed todos that have show_from set. These could have been left over from before the AASM migration
|
||||
Todo.completed.find(:all, :conditions =>[ "NOT(show_from IS NULL)"]).each {|t| t.show_from=nil; t.save!}
|
||||
puts "-- Generating new column values from notes. This may take a while."
|
||||
# Call save! on each todo to force generation of rendered_todos
|
||||
i=0; max = Todo.all.count; start = Time.now
|
||||
Todo.all.each do |todo|
|
||||
todo.save(false)
|
||||
i = i + 1
|
||||
if i%250==0
|
||||
elapsed_sec = (Time.now-start)
|
||||
remaining = (elapsed_sec / i)*(max-i)
|
||||
puts "Progress: #{i} / #{max} (#{(i.to_f/max.to_f*100.0).floor}%) ETA=#{remaining.floor}s"
|
||||
end
|
||||
end
|
||||
puts "Done: #{i} / #{max}"
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :todos, 'rendered_notes'
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue