| | 56 | end |
|---|
| | 57 | end |
|---|
| | 58 | |
|---|
| | 59 | # Returns all records modified or created after the specified time. |
|---|
| | 60 | # Used by the rake rebuild task to find models that need to be updated in |
|---|
| | 61 | # the index after the rebuild finished because they changed while the |
|---|
| | 62 | # rebuild was running. |
|---|
| | 63 | # Override if your models don't stick to the created_at/updated_at |
|---|
| | 64 | # convention. |
|---|
| | 65 | def records_modified_since(time) |
|---|
| | 66 | condition = [] |
|---|
| | 67 | %w(updated_at created_at).each do |col| |
|---|
| | 68 | condition << "#{col} >= ?" if column_names.include? col |
|---|
| | 69 | end |
|---|
| | 70 | if condition.empty? |
|---|
| | 71 | logger.warn "#{self.name}: Override records_modified_since(time) to keep the index up to date with records changed during rebuild." |
|---|
| | 72 | [] |
|---|
| | 73 | else |
|---|
| | 74 | find :all, :conditions => [ condition.join(' AND '), *([time]*condition.size) ] |
|---|