summaryrefslogtreecommitdiff
path: root/modules/field/field.attach.inc
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-17 03:12:17 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-17 03:12:17 +0000
commite9c3a69612d4e1efcf94ec990083b279c346239a (patch)
treea0aca63844a0a6c8f382e5580dc69622e94fee7e /modules/field/field.attach.inc
parent538cfe9150623d4d522221f252fad2daac52c35b (diff)
downloadbrdo-e9c3a69612d4e1efcf94ec990083b279c346239a.tar.gz
brdo-e9c3a69612d4e1efcf94ec990083b279c346239a.tar.bz2
#456488 by yched: Only cache field data for current revision.
Diffstat (limited to 'modules/field/field.attach.inc')
-rw-r--r--modules/field/field.attach.inc44
1 files changed, 23 insertions, 21 deletions
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 92bcbb068..82710c70e 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -332,24 +332,32 @@ function _field_attach_form($obj_type, $object, &$form, $form_state) {
* set as an empty array.
*/
function _field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT) {
- $queried_objects = array();
+ $load_current = $age == FIELD_LOAD_CURRENT;
$info = field_info_fieldable_types($obj_type);
- $cacheable = isset($info['cacheable']) ? $info['cacheable'] : FALSE;
+ $cacheable = $load_current && $info['cacheable'];
+
+ $queried_objects = array();
// Fetch avaliable objects from cache.
- foreach ($objects as $object) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
- if ($cacheable && $cached = cache_get("field:$obj_type:$id:$vid", 'cache_field')) {
- foreach ($cached->data as $field_name => $items) {
- $object->$field_name = $items;
+ if ($cacheable) {
+ foreach ($objects as $id => $object) {
+ $cid = "field:$obj_type:$id";
+ if ($cached = cache_get($cid, 'cache_field')) {
+ foreach ($cached->data as $key => $value) {
+ $object->$key = $value;
+ }
+ }
+ else {
+ $queried_objects[$id] = $objects[$id];
}
}
- else {
- $queried_objects[$id] = $object;
- }
+ }
+ else {
+ $queried_objects = $objects;
}
+
// Fetch other objects from the database.
if ($queried_objects) {
// The invoke order is:
@@ -389,7 +397,7 @@ function _field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT) {
foreach ($instances as $instance) {
$data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
}
- $cid = "field:$obj_type:$id:$vid";
+ $cid = "field:$obj_type:$id";
cache_set($cid, $data, 'cache_field');
}
}
@@ -577,7 +585,7 @@ function _field_attach_insert($obj_type, &$object) {
list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
if ($cacheable) {
- cache_clear_all("field:$obj_type:$id:", 'cache_field', TRUE);
+ cache_clear_all("field:$obj_type:$id", 'cache_field');
}
}
@@ -590,7 +598,6 @@ function _field_attach_insert($obj_type, &$object) {
* The object with fields to save.
*/
function _field_attach_update($obj_type, &$object) {
-
_field_invoke('update', $obj_type, $object);
// Let other modules act on updating the object, accumulating saved
@@ -606,7 +613,7 @@ function _field_attach_update($obj_type, &$object) {
list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
if ($cacheable) {
- cache_clear_all("field:$obj_type:$id:$vid", 'cache_field');
+ cache_clear_all("field:$obj_type:$id", 'cache_field');
}
}
@@ -631,7 +638,7 @@ function _field_attach_delete($obj_type, &$object) {
list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
if ($cacheable) {
- cache_clear_all("field:$obj_type:$id:", 'cache_field', TRUE);
+ cache_clear_all("field:$obj_type:$id", 'cache_field');
}
}
@@ -653,11 +660,6 @@ function _field_attach_delete_revision($obj_type, &$object) {
$function = $module . '_field_attach_delete_revision';
$function($obj_type, $object);
}
-
- list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
- if ($cacheable) {
- cache_clear_all("field:$obj_type:$id:$vid", 'cache_field');
- }
}
/**
@@ -816,7 +818,7 @@ function _field_attach_extract_ids($object_type, $object) {
// If no bundle key provided, then we assume a single bundle, named after the
// type of the object.
$bundle = $info['bundle key'] ? $object->{$info['bundle key']} : $object_type;
- $cacheable = isset($info['cacheable']) ? $info['cacheable'] : FALSE;
+ $cacheable = $info['cacheable'];
return array($id, $vid, $bundle, $cacheable);
}