Skip to content

Commit 597abcd

Browse files
committed
Use _load_from_sql instead of send(:instantiate)
These are both private APIs, but _load_from_sql will give us even more standard behaviour (this is what find_by_sql calls) including emitting the instantiation.active_record notification. This may be faster in some cases since _load_from_sql includes a fast path for when an inheritance column isn't present.
1 parent 10d2c26 commit 597abcd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/github/sql.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,11 @@ def models(klass)
211211
return [] if frozen?
212212

213213
# Use select_all to retrieve hashes for each row instead of arrays of values.
214-
@models = connection.
215-
select_all(query, "#{klass.name} Load via #{self.class.name}").
216-
map { |record| klass.send :instantiate, record }
214+
result_set = connection.
215+
select_all(query, "#{klass.name} Load via #{self.class.name}")
216+
217+
# This is a private Rails API and should ideally not be used
218+
@models = klass._load_from_sql(result_set)
217219

218220
retrieve_found_row_count
219221
freeze

0 commit comments

Comments
 (0)