Skip to content

Commit b377e1d

Browse files
committed
Minor performance improvements
1 parent e1e9821 commit b377e1d

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

lib/optimizations/columns/attributes_proxy.rb

+3-22
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,18 @@ class ScroogedAttributes < Hash
3434
attr_accessor :fully_fetched, :klass, :updateable_result_set
3535

3636
def self.setup(record, klass, updateable_result_set)
37-
hash = new.replace(record)
37+
hash = new.replace(klass.columns_hash.merge(record))
3838
hash.fully_fetched = false
3939
hash.klass = klass
4040
hash.updateable_result_set = updateable_result_set
4141
hash
4242
end
4343

44-
# Delegate Hash keys to all defined columns
45-
#
46-
def keys
47-
@klass.column_names
48-
end
49-
50-
# Let #has_key? consider defined columns
51-
#
52-
def has_key?(attr_name)
53-
@klass.columns_hash.has_key?(attr_name)
54-
end
55-
56-
alias_method :include?, :has_key?
57-
alias_method :key?, :has_key?
58-
alias_method :member?, :has_key?
59-
6044
# Lazily augment and load missing attributes
6145
#
6246
def [](attr_name)
63-
if interesting_for_scrooge?( attr_name )
47+
return nil unless has_key?(attr_name)
48+
if !scrooge_columns.include?(attr_name)
6449
augment_callsite!( attr_name )
6550
fetch_remaining
6651
add_to_scrooge_columns(attr_name)
@@ -131,10 +116,6 @@ def fetch_remaining!( columns_to_fetch )
131116
@updateable_result_set.reload_columns!(columns_to_fetch)
132117
end
133118

134-
def interesting_for_scrooge?( attr_name )
135-
@klass.columns_hash.has_key?(attr_name) && !scrooge_columns.include?(attr_name)
136-
end
137-
138119
def augment_callsite!( attr_name )
139120
@klass.scrooge_seen_column!(callsite_signature, attr_name)
140121
end

lib/optimizations/result_sets/updateable_result_set.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def update_with(remaining_attributes)
8686
remaining_attributes.each do |r_id, r_att|
8787
old_attributes = current_attributes[r_id]
8888
if old_attributes
89-
old_attributes.update(r_att.merge(old_attributes)) # must call update, do not use reverse_update
89+
old_attributes.update(r_att)
9090
end
9191
end
9292
end

lib/scrooge.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class << self
2727
#
2828
def find_by_sql(sql)
2929
if scope_with_scrooge?(sql)
30-
find_by_sql_without_scrooge(sql)
30+
find_by_sql_with_scrooge(sql)
3131
else
3232
find_by_sql_without_scrooge(sql)
3333
end

0 commit comments

Comments
 (0)