This affects CCK-2 and CCK-3 for drupal 6 and might affect Drupal 7's CCK module (I haven't checked).
While trying to solve problems with http://drupal.org/node/300084, I began walking through code and adding watchdog() prints on data.
I discovered that when refreshing a node page for a node of Content Type A, all other content Types (say Type A to Type 1 Million) get loaded and processed by the following query:
<?php
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name");
?>Which with the nested fieldgroup patch looks like:
<?php
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY type_name, weight");
?>This is wasteful of resources.
If a website had 500 node types (WOW!) this would be loading and looping through 500 node types and all of their individual fields when all we should be looping through is data for the content type that node represents.
The fieldgroups_groups() function does get the content_type passed to it.
Why not use that???
Heres an approach I think would be better:
<?php
if (empty($content_type)){
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name");
} else {
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} WHERE type_name like '%s' ORDER BY weight, group_name", $content_type);
}
?>and for the nested fieldgroup patch:
<?php
if (empty($content_type)){
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY type_name, weight");
} else {
$result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} WHERE type_name like '%s' ORDER BY type_name, weight", $content_type);
}
?>Doing this only loads and processes data for the current content type instead of for every content type that exists in the database.
Is there any case where one would want to load all content types here?
If there is, then I suggest breaking this function into two separate functions such that we avoid the potential overhead where unnecessary.