Skip to content
Snippets Groups Projects
Commit 616f2ca8 authored by Alex Barth's avatar Alex Barth
Browse files

#707098 Improve performance of nodeapi and access checks.

parent 90cf9016
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
Feeds 6.x 1.0 xxxxx xx, 2010-xx-xx
----------------------------------
- #707098 alex_b: Improve performance of nodeapi and access checks.
- #726012 alex_b: Fix RSS descriptions not being reset in
common_syndication_parser.inc.
- alex_b: Fix a typo in the return value of process() in FeedsTermProcessor.
......
......@@ -183,16 +183,13 @@ function feeds_access($action, $param) {
/**
* Menu access callback.
*
* @todo Create cached function that returns available configurations
* and use it for enumerating feed configuration ids.
*/
function feeds_page_access() {
if (user_access('administer feeds')) {
return TRUE;
}
foreach (feeds_importer_load_all() as $importer) {
if (user_access('import '. $importer->id .' feed')) {
foreach (feeds_enabled_importers() as $id) {
if (user_access("import $id feed")) {
return TRUE;
}
}
......@@ -468,39 +465,18 @@ function feeds_importer_load_all($load_disabled = FALSE) {
}
/**
* Return whether a importer is enabled or not.
*
* Use only for importer configurations that ship with feeds. This function
* assumes that importers are initially off and then enabled manually on
* admin/build/feeds.
* Get an array of enabled importer ids.
*
* @return
* TRUE if the importer is enabled, FALSE if not.
*/
function feeds_importer_enabled($id) {
// 'default_feeds_importer' variable is used internally by CTools to determine
// the enabled/disabled state of a configuration. This variable may not be
// completely populated.
$disabled = variable_get('default_feeds_importer', FALSE);
if ($disabled === FALSE) {
$disabled = array();
foreach (feeds_importer_load_all() as $importer) {
$disabled[$importer->id] = $disabled->disabled;
}
variable_set('default_feeds_importer', $disabled);
}
// If disabled is not present, assume that importer configuration is disabled.
if (!isset($disabled[$id])) {
return FALSE;
}
return !$disabled[$id];
* An array where the values contain ids of enabled importers.
*/
function feeds_enabled_importers() {
return array_keys(_feeds_importer_digest());
}
/**
* Get a an enabled importer configuration by content type.
*
* @todo speed this up by DB caching the result.
*
* @param $content_type
* A node type string.
*
......@@ -509,17 +485,42 @@ function feeds_importer_enabled($id) {
* FALSE otherwise.
*/
function feeds_get_importer_id($content_type) {
static $ids = array();
if (!isset($ids[$content_type])) {
$ids[$content_type] = FALSE;
foreach (feeds_importer_load_all() as $importer) {
if ((!$importer->disabled) && $importer->config['content_type'] == $content_type) {
$ids[$content_type] = $importer->id;
break;
$importers = array_flip(_feeds_importer_digest());
return isset($importers[$content_type]) ? $importers[$content_type] : FALSE;
}
/**
* Helper function for feeds_get_importer_id() and feeds_enabled_importers().
*/
function _feeds_importer_digest() {
$importers = &ctools_static(__FUNCTION__);
if ($importers === NULL) {
if ($cache = cache_get(__FUNCTION__)) {
$importers = $cache->data;
}
else {
$importers = array();
foreach (feeds_importer_load_all() as $importer) {
$importers[$importer->id] = $importer->config['content_type'];
}
cache_set(__FUNCTION__, $importers);
}
}
return $ids[$content_type];
return $importers;
}
/**
* Reset importer caches. Call when enabling/disabling importers.
*/
function feeds_cache_clear($rebuild_menu = TRUE) {
cache_clear_all('_feeds_importer_digest', 'cache');
ctools_static_reset('_feeds_importer_digest');
ctools_include('export');
ctools_export_load_object_reset('feeds_importer');
node_get_types('types', NULL, TRUE);
if ($rebuild_menu) {
menu_rebuild();
}
}
/**
......
......@@ -13,7 +13,7 @@ require_once(dirname(__FILE__) .'/feeds_defaults.features.inc');
*/
function feeds_defaults_node_info() {
$items = array();
if (feeds_importer_enabled('feed')) {
if (in_array('feed', feeds_enabled_importers())) {
$items['feed'] = array(
'name' => t('Feed'),
'module' => 'node',
......@@ -35,7 +35,7 @@ function feeds_defaults_node_info() {
'locked' => TRUE,
);
}
if (feeds_importer_enabled('feed_fast')) {
if (in_array('feed_fast', feeds_enabled_importers())) {
$items['feed_fast'] = array(
'name' => t('Fast feed'),
'module' => 'node',
......
......@@ -139,15 +139,7 @@ function feeds_ui_overview_form_submit($form, &$form_state) {
$disabled[$importer->id] = !$form_state['values'][$importer->id];
}
variable_set('default_feeds_importer', $disabled);
// Clear caches: reset export cache, as objects have been enabled/disabled,
// reset node type cache, as some features provide content types, rebuild
// menu as content type changes or importer enabling/disabling can have
// impact on node/add/ or import/.
ctools_include('export');
ctools_export_load_object_reset('feeds_importer');
node_get_types('types', NULL, TRUE);
menu_rebuild();
feeds_cache_clear();
}
/**
......@@ -225,6 +217,7 @@ function feeds_ui_create_form_submit($form, &$form_state) {
drupal_set_message(t('A clone of the !name configuration has been created.', array('!name' => $form['#from_importer']->config['name'])));
}
$form_state['redirect'] = 'admin/build/feeds/edit/'. $importer->id;
feeds_cache_clear();
}
/**
......@@ -257,7 +250,7 @@ function feeds_ui_delete_form_submit($form, &$form_state) {
$form['#importer']->delete();
// Clear cache, deleting a configuration may have an affect on menu tree.
menu_rebuild();
feeds_cache_clear();
}
/**
......
......@@ -238,4 +238,5 @@ function feeds_config_form_submit($form, &$form_state) {
$form['#configurable']->addConfig($form_state['values']);
$form['#configurable']->save();
drupal_set_message(t('Your changes have been saved.'));
feeds_cache_clear(FALSE);
}
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