lib/rubyrep/logged_change.rb in rubyrep-1.0.1 vs lib/rubyrep/logged_change.rb in rubyrep-1.0.2

- old
+ new

@@ -44,11 +44,11 @@ # * key: table name # * value: 2nd level tree # 2nd level tree: # * key: the change_key value of the according change log records. # * value: - # The according change log record (column_name => value hash). + # An array of according change log records (column_name => value hash). # Additional entry of each change log hash: # * key: 'array_index' # * value: index to the change log record in +change_array+ attr_accessor :change_tree @@ -82,9 +82,22 @@ def update(options = {:forced => false, :expire_time => 1}) return unless options[:forced] or Time.now - self.last_updated >= options[:expire_time] self.last_updated = Time.now + # First, let's use a LIMIT clause (via :row_buffer_size option) to verify + # if there are any pending changes. + # (If there are many pending changes, this is (at least with PostgreSQL) + # much faster.) + cursor = connection.select_cursor( + :table => change_log_table, + :from => {'id' => current_id}, + :exclude_starting_row => true, + :row_buffer_size => 1 + ) + return unless cursor.next? + + # Something is here. Let's actually load it. cursor = connection.select_cursor( :table => change_log_table, :from => {'id' => current_id}, :exclude_starting_row => true, :type_cast => true \ No newline at end of file