Permalink
Browse files

Minor performance improvements

  • Loading branch information...
1 parent e1e9821 commit b377e1dbf5a771f2b9cd7a8bc7fae44419e4c99c @sdsykes sdsykes committed Apr 3, 2009
@@ -34,33 +34,18 @@ class ScroogedAttributes < Hash
attr_accessor :fully_fetched, :klass, :updateable_result_set
def self.setup(record, klass, updateable_result_set)
- hash = new.replace(record)
+ hash = new.replace(klass.columns_hash.merge(record))
hash.fully_fetched = false
hash.klass = klass
hash.updateable_result_set = updateable_result_set
hash
end
- # Delegate Hash keys to all defined columns
- #
- def keys
- @klass.column_names
- end
-
- # Let #has_key? consider defined columns
- #
- def has_key?(attr_name)
- @klass.columns_hash.has_key?(attr_name)
- end
-
- alias_method :include?, :has_key?
- alias_method :key?, :has_key?
- alias_method :member?, :has_key?
-
# Lazily augment and load missing attributes
#
def [](attr_name)
- if interesting_for_scrooge?( attr_name )
+ return nil unless has_key?(attr_name)
+ if !scrooge_columns.include?(attr_name)
augment_callsite!( attr_name )
fetch_remaining
add_to_scrooge_columns(attr_name)
@@ -131,10 +116,6 @@ def fetch_remaining!( columns_to_fetch )
@updateable_result_set.reload_columns!(columns_to_fetch)
end
- def interesting_for_scrooge?( attr_name )
- @klass.columns_hash.has_key?(attr_name) && !scrooge_columns.include?(attr_name)
- end
-
def augment_callsite!( attr_name )
@klass.scrooge_seen_column!(callsite_signature, attr_name)
end
@@ -86,7 +86,7 @@ def update_with(remaining_attributes)
remaining_attributes.each do |r_id, r_att|
old_attributes = current_attributes[r_id]
if old_attributes
- old_attributes.update(r_att.merge(old_attributes)) # must call update, do not use reverse_update
+ old_attributes.update(r_att)
end
end
end
View
@@ -27,7 +27,7 @@ class << self
#
def find_by_sql(sql)
if scope_with_scrooge?(sql)
- find_by_sql_without_scrooge(sql)
+ find_by_sql_with_scrooge(sql)
else
find_by_sql_without_scrooge(sql)
end

0 comments on commit b377e1d

Please sign in to comment.