Index: tagadelic.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/tagadelic/tagadelic.module,v retrieving revision 1.38 diff -u -r1.38 tagadelic.module --- tagadelic.module 15 Sep 2007 09:29:12 -0000 1.38 +++ tagadelic.module 12 Dec 2007 06:19:26 -0000 @@ -94,6 +94,14 @@ '#default_value' => variable_get('tagadelic_levels', 6), '#description' => t('The number of levels between the least popular tags and the most popular ones. Different levels will be assigned a different class to be themed in tagadelic.css'), ); + $options = array('cache' => t('Cache'), 'nocache' => t('Don\'t Cache')); + $form['tagadelic_caching'] = array( + '#type' => 'radios', + '#title' => t('Tagadelic caching'), + '#options' => $options, + '#default_value' => variable_get('tagadelic_caching', 'nocache'), + '#description' => t('Determines whether to cache the calculation results.'), + ); return system_settings_form($form); } @@ -207,28 +215,30 @@ * @return An unordered array with tags-objects, containing the attribute $tag->weight; */ function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) { + $docache = variable_get('tagadelic_caching', 'nocache'); + // build the options so we can cache multiple versions $options = implode($vids) .'_'. $steps .'_'. $size; - - // Check if the cache exists $cache_name = 'tagadelic_cache_'. $options; - $cache = cache_get($cache_name); + + if ($docache == 'cache') { + $cache = cache_get($cache_name); - // make sure cache has data - if ($cache->data) { - $tags = unserialize($cache->data); + // make sure cache has data + if ($cache->data) { + $tags = unserialize($cache->data); + return $tags; + } } - else { - if (!is_array($vids) || count($vids) == 0) { - return array(); - } - $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size); + if (!is_array($vids) || count($vids) == 0) { + return array(); + } + $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size); - $tags = tagadelic_build_weighted_tags($result, $steps); + $tags = tagadelic_build_weighted_tags($result, $steps); - cache_set($cache_name, 'cache', serialize($tags)); - } + cache_set($cache_name, 'cache', serialize($tags)); return $tags; }