diff --git a/ctools.install b/ctools.install index 47f01fb..34ba1d6 100644 --- a/ctools.install +++ b/ctools.install @@ -40,7 +40,23 @@ function ctools_requirements($phase) { * Implements hook_schema(). */ function ctools_schema() { - return ctools_schema_4(); + return ctools_schema_5(); +} + +/** + * Version 5 of the CTools schema. + */ +function ctools_schema_5() { + $schema = ctools_schema_4(); + + // Replace the three separate primary keys and add a single one. + $schema['ctools_object_cache']['fields']['cid'] = $schema['ctools_object_cache']['fields']['name']; + unset($schema['ctools_object_cache']['fields']['sid']); + unset($schema['ctools_object_cache']['fields']['name']); + unset($schema['ctools_object_cache']['fields']['obj']); + $schema['ctools_object_cache']['primary key'] = array('cid'); + + return $schema; } /** @@ -127,12 +143,6 @@ function ctools_schema_1() { $schema['ctools_object_cache'] = array( 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'), 'fields' => array( - 'sid' => array( - 'type' => 'varchar', - 'length' => '64', - 'not null' => TRUE, - 'description' => 'The session ID this cache object belongs to.', - ), 'name' => array( 'type' => 'varchar', 'length' => '32', @@ -286,3 +296,18 @@ function ctools_update_7002() { 'not null' => TRUE, )); } + +/** + * Combine the three 'ctools_object_cache' key fields into one. + */ +function ctools_update_7003() { + db_delete('ctools_object_cache')->execute(); + db_change_field('ctools_object_cache', 'name', 'cid', array( + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE, + 'description' => 'The primary key of this object.', + )); + db_drop_primary_key('ctools_object_cache'); + db_add_primary_key('ctools_object_cache', array('cid')); +} diff --git a/includes/object-cache.inc b/includes/object-cache.inc index 614c56f..eeb04f4 100644 --- a/includes/object-cache.inc +++ b/includes/object-cache.inc @@ -43,7 +43,12 @@ function ctools_object_cache_get($obj, $name, $skip_cache = FALSE, $sid = NULL) } if (!array_key_exists($key, $cache)) { - $data = db_query('SELECT * FROM {ctools_object_cache} WHERE sid = :session_id AND obj = :object AND name = :name', array(':session_id' => $sid, ':object' => $obj, ':name' => $name)) + $data = db_query('SELECT * + FROM {ctools_object_cache} + WHERE cid = :cid', + array( + ':cid' => implode(':', array($sid, $obj, $name)), + )) ->fetchObject(); if ($data) { $cache[$key] = unserialize($data->data); @@ -82,9 +87,7 @@ function ctools_object_cache_set($obj, $name, $cache, $sid = NULL) { db_insert('ctools_object_cache') ->fields(array( - 'sid' => $sid, - 'obj' => $obj, - 'name' => $name, + 'cid' => implode(':', array($sid, $obj, $name)), 'data' => serialize($cache), 'updated' => REQUEST_TIME, )) @@ -110,9 +113,7 @@ function ctools_object_cache_clear($obj, $name, $sid = NULL) { } db_delete('ctools_object_cache') - ->condition('sid', $sid) - ->condition('obj', $obj) - ->condition('name', $name) + ->condition('cid', implode(':', array($sid, $obj, $name))) ->execute(); // Ensure the static cache is emptied of this obj:name set. drupal_static_reset('ctools_object_cache_get'); @@ -178,9 +179,9 @@ function ctools_object_cache_test_objects($obj, $names) { * The name of the object being removed. */ function ctools_object_cache_clear_all($obj, $name) { + $cid = implode(':', array('', $obj, $name)); db_delete('ctools_object_cache') - ->condition('obj', $obj) - ->condition('name', $name) + ->condition('cid', db_like('%' . $cid), 'LIKE'), ->execute(); // Ensure the static cache is emptied of this obj:name set. $cache = &drupal_static('ctools_object_cache_get', array());