Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Apr 2009 at 15:54 UTC
Updated:
17 Jun 2009 at 10:10 UTC
field_attach_load() does a lot of "call a function, get an array result, and then iterate over the array to merge the results with others." e.g.:
// Invoke the storage engine's hook_field_storage_load(): the field storage
// engine loads the rest.
$additions = module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_load', $obj_type, $queried_objects, $age, $skip_fields);
// First, merge the additions from the storage engine.
foreach ($additions as $id => $obj_additions) {
foreach ($obj_additions as $key => $value) {
$queried_objects[$id]->$key = $value;
}
}
Instead, I suggest that we pass the collection array directly to each hook by reference and let them build it up directly, reducing data copying and iterations. Note that hook_field_attach_pre_load() already works this way.
Yes, this requires more cooperation among modules, but we already have hooks that let anyone stomp all over anything anyway, so...
Comments
Comment #1
moshe weitzman commentedRight - drupal_alter() just passes an object by reference and it works well in practice. Perhaps use that.
Comment #2
yched commentedYes, I've been thinking about this and couldn't remember why 'gather data to cache' forced us to have load hooks return the results instead of altering $object like for other ops.
I was thinking of refactoring this along with #362024: Field Attach: Make hook_field_load() be 'multiple' like field_attach_load()
Comment #3
catchnode, taxonomy and vocabulary _load() hooks also act on (arrays of) objects by reference, so it'd be consistent with that too.
Comment #4
bjaspan commentedyched is right, this really should be done in conjunction with #362024: Field Attach: Make hook_field_load() be 'multiple' like field_attach_load(). Let's revisit or close this issue when that one is done.
Comment #5
jjkd commentedLooks like #362024: Field Attach: Make hook_field_load() be 'multiple' like field_attach_load() is done, do we revisit or close this one?
Comment #6
yched commentedYes, this was fixed in #362024: Field Attach: Make hook_field_load() be 'multiple' like field_attach_load().