- Patch #291064 by mustafau: improve performance of aggregator by storing an md5 hash for the feed.
parent
e21ad98d92
commit
73f98066f5
|
@ -20,7 +20,7 @@ function aggregator_admin_overview() {
|
|||
* The page HTML.
|
||||
*/
|
||||
function aggregator_view() {
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
|
||||
$result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
|
||||
|
||||
$output = '<h3>' . t('Feed overview') . '</h3>';
|
||||
|
||||
|
|
|
@ -158,6 +158,13 @@ function aggregator_schema() {
|
|||
'size' => 'big',
|
||||
'description' => t('An image representing the feed.'),
|
||||
),
|
||||
'hash' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => t('Calculated md5 hash of the feed data, used for validating cache.'),
|
||||
),
|
||||
'etag' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
|
@ -247,3 +254,12 @@ function aggregator_schema() {
|
|||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add hash column to aggregator_feed table.
|
||||
*/
|
||||
function aggregator_update_7000() {
|
||||
$ret = array();
|
||||
db_add_field($ret, 'aggregator_feed', 'hash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
|
||||
return $ret;
|
||||
}
|
||||
|
|
|
@ -452,7 +452,7 @@ function aggregator_remove($feed) {
|
|||
db_query('DELETE FROM {aggregator_category_item} WHERE ' . implode(' OR ', $items));
|
||||
}
|
||||
db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
|
||||
db_query("UPDATE {aggregator_feed} SET checked = 0, etag = '', modified = 0 WHERE fid = %d", $feed['fid']);
|
||||
db_query("UPDATE {aggregator_feed} SET checked = 0, hash = '', etag = '', modified = 0 WHERE fid = %d", $feed['fid']);
|
||||
drupal_set_message(t('The news items from %site have been removed.', array('%site' => $feed['title'])));
|
||||
}
|
||||
|
||||
|
@ -603,6 +603,16 @@ function aggregator_refresh($feed) {
|
|||
case 200:
|
||||
case 302:
|
||||
case 307:
|
||||
// We store the md5 hash of feed data in the database. When refreshing a
|
||||
// feed we compare stored hash and new hash calculated from downloaded
|
||||
// data. If both are equal we say that feed is not updated.
|
||||
$md5 = md5($result->data);
|
||||
if ($feed['hash'] == $md5) {
|
||||
db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']);
|
||||
drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed['title'])));
|
||||
break;
|
||||
}
|
||||
|
||||
// Filter the input data.
|
||||
if (aggregator_parse_feed($result->data, $feed)) {
|
||||
$modified = empty($result->headers['Last-Modified']) ? 0 : strtotime($result->headers['Last-Modified']);
|
||||
|
@ -628,7 +638,7 @@ function aggregator_refresh($feed) {
|
|||
|
||||
$etag = empty($result->headers['ETag']) ? '' : $result->headers['ETag'];
|
||||
// Update the feed data.
|
||||
db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $etag, $modified, $feed['fid']);
|
||||
db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', hash = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $md5, $etag, $modified, $feed['fid']);
|
||||
|
||||
// Clear the cache.
|
||||
cache_clear_all();
|
||||
|
|
Loading…
Reference in New Issue