-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JBuilder 2.11.3 introduces an extra DB query when rendering collection partials #514
Comments
Also experiencing the same issue with the additional |
Also before, the |
Same error for me, 2.11.2 works, but 2.11.3 is broken. As pointed out by @tf , just implementing |
Turn page_types into array since JBuilder 2.11.3 (rails/jbuilder#501) requires collection to respond to `empty?`, which `Enumerable` does not provide. See also rails/jbuilder#514 REDMINE-19357
Turn enumerables into arrays since JBuilder 2.11.3 (rails/jbuilder#501) requires collection to respond to `empty?`, which `Enumerable` does not provide. See also rails/jbuilder#514 REDMINE-19357
cc @yuki24 |
#524 should address this issue. |
Turn enumerables into arrays since JBuilder 2.11.3 (rails/jbuilder#501) requires collection to respond to `empty?`, which `Enumerable` does not provide. See also rails/jbuilder#514 REDMINE-19357
Ruby Version: 2.7.4
Rails Version: 5.2.6
JBuilder Version: 2.11.3
This was introduced by #501 with the
options[:collection].empty?
call:jbuilder/lib/jbuilder/jbuilder_template.rb
Line 144 in b94394b
When the collection object is an Active Record association relation/collection the
empty?
call introduces aSELECT 1
query statement from this code inActiveRecord::Relation#empty?
:This SQL statement occurs for the case when the collection is not yet loaded; which is very common for the main collection on
index
actions. Theexists?
code is run which is defined inActiveRecord::FinderMethods#exists?
. This causes SQL to be executed viaconnection.select_one
.The extra SQL statement is an unnecessary DB trip across the network when there is data.
For comparison, in JBuild 2.11.2 the same process passes the collection to
array!
which ends up loading the full collection without thisselect_one
call.This is easily reproduced with a controller action such as:
When hit without data the Rails default logger shows:
When run with data, the
SELECT 1
and theSELECT *
are both present:The text was updated successfully, but these errors were encountered: