Skip to content
Snippets Groups Projects
Commit 808eb92d authored by Dave Reid's avatar Dave Reid
Browse files

Issue #1044882 by rfay, Dave Reid: Fixed indexes for {feeds_item} are too long...

Issue #1044882 by rfay, Dave Reid: Fixed indexes for {feeds_item} are too long and can cause problems during install or uninstall.
parent e3201630
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,7 @@ function feeds_schema() {
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 64,
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
......@@ -155,10 +155,10 @@ function feeds_schema() {
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 255)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 255)),
'global_lookup_url' => array('entity_type', array('url', 255)),
'global_lookup_guid' => array('entity_type', array('guid', 255)),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
'global_lookup_url' => array('entity_type', array('url', 128)),
'global_lookup_guid' => array('entity_type', array('guid', 128)),
'imported' => array('imported'),
),
);
......@@ -299,7 +299,7 @@ function feeds_schema() {
* Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
* result.
*/
function feeds_update_7100(&$sandbox) {
function feeds_update_7100() {
$spec = array(
'type' => 'text',
'size' => 'big',
......@@ -322,7 +322,7 @@ function feeds_update_7100(&$sandbox) {
/**
* Add imported timestamp to feeds_source table.
*/
function feeds_update_7201(&$sandbox) {
function feeds_update_7201() {
$spec = array(
'type' => 'int',
'not null' => TRUE,
......@@ -336,13 +336,13 @@ function feeds_update_7201(&$sandbox) {
/**
* Create a single feeds_item table tracking all imports.
*/
function feeds_update_7202(&$sandbox) {
function feeds_update_7202() {
$spec = array(
'description' => 'Tracks items such as nodes, terms, users.',
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 64,
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
......@@ -394,8 +394,8 @@ function feeds_update_7202(&$sandbox) {
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 255)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 255)),
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
'imported' => array('imported'),
),
);
......@@ -411,7 +411,7 @@ function feeds_update_7202(&$sandbox) {
/**
* Add feeds_log table.
*/
function feeds_update_7203(&$sandbox) {
function feeds_update_7203() {
$schema = array(
'description' => 'Table that contains logs of feeds events.',
'fields' => array(
......@@ -488,7 +488,32 @@ function feeds_update_7203(&$sandbox) {
/**
* Add index for looking up by entity_type + url/ guid to feeds_item table.
*/
function feeds_update_7204(&$sandbox) {
db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 255)));
db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 255)));
function feeds_update_7204() {
db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
}
/**
* Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
*/
function feeds_update_7205() {
db_drop_primary_key('feeds_item');
db_drop_index('feeds_item', 'lookup_url');
db_drop_index('feeds_item', 'lookup_guid');
db_drop_index('feeds_item', 'global_lookup_url');
db_drop_index('feeds_item', 'global_lookup_guid');
db_change_field('feeds_item', 'entity_type', 'entity_type', array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
));
db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
db_add_index('feeds_item', 'lookup_url', array('entity_type', 'id', 'feed_nid', array('url', 128)));
db_add_index('feeds_item', 'lookup_guid', array('entity_type', 'id', 'feed_nid', array('guid', 128)));
db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
}
......@@ -444,9 +444,15 @@ function feeds_feeds_plugins() {
* Implements hook_entity_load().
*/
function feeds_entity_load($entities, $type) {
$feed_nids = db_query("SELECT entity_id, feed_nid FROM {feeds_item} WHERE entity_type = :type AND entity_id IN (:ids)", array(':type' => $type, ':ids' => array_keys($entities)))->fetchAllKeyed();
foreach ($feed_nids as $id => $feed_nid) {
$entities[$id]->feed_nid = $feed_nid;
try {
$feed_nids = db_query("SELECT entity_id, feed_nid FROM {feeds_item} WHERE entity_type = :type AND entity_id IN (:ids)", array(':type' => $type, ':ids' => array_keys($entities)))->fetchAllKeyed();
foreach ($feed_nids as $id => $feed_nid) {
$entities[$id]->feed_nid = $feed_nid;
}
}
catch (Exception $e) {
watchdog_exception('feeds', $e);
// Do not re-throw $e.
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment