Index: l10n_community.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.module,v
retrieving revision 1.1.2.23
diff -u -p -r1.1.2.23 l10n_community.module
--- l10n_community.module	10 Sep 2008 10:20:51 -0000	1.1.2.23
+++ l10n_community.module	24 Oct 2008 16:10:56 -0000
@@ -949,3 +949,62 @@ function l10n_community_format_text($str
 
   return "<div class='$class'><span class='string'>$string</span><span class='original hidden'>$original</span></div>";
 }
+
+/*
+ * Compute language community stats
+ *
+ * @param $langcode
+ *   Compute statistics for this language.
+ */
+function l10n_community_get_stats($langcode = NULL) {
+  if (isset($langcode) && !empty($langcode)) {
+    // Compute based on langcode.
+    if ($stats = cache_get('l10n:stats:'.$langcode, 'cache')) {
+      return unserialize($stats->data);
+    } else {
+      $stats = array();
+      $stats['strings'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_string}'));
+      $stats['translations'] = db_result(db_query("SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 0 AND is_active = 1 AND language = '%s'", $langcode));
+      $stats['suggestions'] = db_result(db_query("SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1 AND language = '%s'", $langcode));
+      $stats['users'] = db_result(db_query("SELECT COUNT(DISTINCT uid_entered) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1 AND language = '%s'", $langcode));
+
+      
+      // Cache results for next time. Not setting a timestamp as cache validity
+      // time, we would like to retain control of recalculating these values.
+      cache_set('l10n:stats:'.$langcode, 'cache', serialize($stats), CACHE_PERMANENT);
+      return $stats;
+    }
+  } else {
+    // General community statistics.
+    if ($stats = cache_get('l10n:stats', 'cache')) {
+      return unserialize($stats->data);
+    } else {
+      $stats = array();
+      $stats['users'] = (int) db_result(db_query('SELECT COUNT(DISTINCT uid_entered) FROM {l10n_community_translation} GROUP BY uid_entered'));
+      $stats['projects'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_project}'));
+      $stats['files'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_file}'));
+      $stats['strings'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_string}'));
+      $stats['translations'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 0 AND is_active = 1'));
+      $stats['suggestions'] = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1'));
+
+      // Cache results for next time. Not setting a timestamp as cache validity
+      // time, we would like to retain control of recalculating these values.
+      cache_set('l10n:stats', 'cache', serialize($stats), CACHE_PERMANENT);
+
+      return $stats;
+    }
+  }
+}
+
+/*
+ * Implementation of hook_cron().
+ *
+ * Clear project and language stats every hour.
+ */
+function l10n_community_cron() {
+  $lastrun = variable_get('l10n_cron_stats', 1);
+  if ($_SERVER['REQUEST_TIME'] - $lastrun > 3600) {
+    cache_clear_all('l10n:stats', 'cache', TRUE);
+    variable_set('l10n_cron_stats', $_SERVER['REQUEST_TIME']);
+  }
+}
Index: pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/pages.inc,v
retrieving revision 1.1.2.20
diff -u -p -r1.1.2.20 pages.inc
--- pages.inc	10 Sep 2008 09:06:41 -0000	1.1.2.20
+++ pages.inc	24 Oct 2008 16:10:56 -0000
@@ -142,18 +142,16 @@ function l10n_community_overview_languag
   );
   $output .= str_replace('class="admin-panel"', 'class="admin-panel admin-panel-contribute"', theme('admin_block', $block));
 
-  $strings = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_string}'));
-  $translations = db_result(db_query("SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 0 AND is_active = 1 AND language = '%s'", $langcode));
-  $suggestions = db_result(db_query("SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1 AND language = '%s'", $langcode));
-  $users = db_result(db_query("SELECT COUNT(DISTINCT uid_entered) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1 AND language = '%s'", $langcode));
+  $stats_numbers = l10n_community_get_stats($langcode);
+
   $block = array(
     'title' => t('Progress status'),
     'description' => t('Status overview'),
     'content' => theme('item_list', array(
-      format_plural($users, '1 contributor', '@count contributors'),
-      format_plural($strings, '1 string to translate', '@count strings to translate'),
-      format_plural($translations, '1 translation recorded', '@count translations recorded'),
-      format_plural($suggestions, '1 suggestion awaiting approval', '@count suggestions awaiting approval'),
+      format_plural($stats_numbers['users'], '1 contributor', '@count contributors'),
+      format_plural($stats_numbers['strings'], '1 string to translate', '@count strings to translate'),
+      format_plural($stats_numbers['translations'], '1 translation recorded', '@count translations recorded'),
+      format_plural($stats_numbers['suggestions'], '1 suggestion awaiting approval', '@count suggestions awaiting approval'),
     ))
   );
   $output .= theme('admin_block', $block);
Index: welcome.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/welcome.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 welcome.inc
--- welcome.inc	25 Apr 2008 18:33:37 -0000	1.1.2.7
+++ welcome.inc	24 Oct 2008 16:10:56 -0000
@@ -34,22 +34,17 @@ function l10n_community_welcome_page() {
       format_plural($groups, '1 translation group', '@count translation groups'),
     );
   }
-  $users = (int) db_result(db_query('SELECT COUNT(DISTINCT uid_entered) FROM {l10n_community_translation} GROUP BY uid_entered'));
-  $projects = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_project}'));
-  $files = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_file}'));
-  $strings = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_string}'));
-  $translations = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 0 AND is_active = 1'));
-  $suggestions = db_result(db_query('SELECT COUNT(*) FROM {l10n_community_translation} WHERE is_suggestion = 1 AND is_active = 1'));
+  $stats_numbers = l10n_community_get_stats();
   $block = array(
     'title' => t('Quick stats'),
     'description' => t('Some facts about this community'),
     'content' => theme('item_list', array_merge($stats, array(
-      format_plural($users, '1 contributor', '@count contributors'),
-      format_plural($projects, '1 project managed', '@count projects managed'),
-      format_plural($files, '1 file scanned', '@count files scanned'),
-      format_plural($strings, '1 string to translate', '@count strings to translate'),
-      format_plural($translations, '1 translation recorded', '@count translations recorded'),
-      format_plural($suggestions, '1 suggestion awaiting approval', '@count suggestions awaiting approval'),
+      format_plural($stats_numbers['users'], '1 contributor', '@count contributors'),
+      format_plural($stats_numbers['projects'], '1 project managed', '@count projects managed'),
+      format_plural($stats_numbers['files'], '1 file scanned', '@count files scanned'),
+      format_plural($stats_numbers['strings'], '1 string to translate', '@count strings to translate'),
+      format_plural($stats_numbers['translations'], '1 translation recorded', '@count translations recorded'),
+      format_plural($stats_numbers['suggestions'], '1 suggestion awaiting approval', '@count suggestions awaiting approval'),
     ))),
   );
   $output .= theme('admin_block', $block);
