Index: feedapi.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feedapi/feedapi.install,v
retrieving revision 1.5.2.15
diff -r1.5.2.15 feedapi.install
24a25,32
>       db_query("CREATE TABLE {feedapi_stat} (
>         id INT(10) unsigned NOT NULL default '0',
>         type VARCHAR(64) NOT NULL,
>         timestamp INT(11) NOT NULL,
>         time VARCHAR(20) NOT NULL,
>         value INT(11) NOT NULL,
>         INDEX (id, type, timestamp, time));
>       ");
40a49,59
>       db_query("CREATE TABLE feedapi_stat (
>         id int NOT NULL default '0',
>         type VARCHAR(64) NOT NULL,
>         timestamp INT NOT NULL,
>         time VARCHAR(20) NOT NULL,
>         value INT NOT NULL)
>       ");
>       db_query("CREATE INDEX type_index on feedapi_stat(type)");
>       db_query("CREATE INDEX timestamp_index on feedapi_stat(timestamp)");
>       db_query("CREATE INDEX time_index on feedapi_stat(time)");
>       db_query("CREATE INDEX id_index on feedapi_stat(id)");
112c131
<     $ret = array();
---
>   $ret = array();
167a187,231
> 
> function feedapi_update_4() {
>   $ret = array();
>   switch ($GLOBALS['db_type']) {
>     case 'mysqli':
>     case 'mysql':
>        db_query("CREATE TABLE {feedapi_stat} (
>         id INT(10) unsigned NOT NULL default '0',
>         type VARCHAR(64) NOT NULL,
>         timestamp INT(11) NOT NULL,
>         time VARCHAR(20) NOT NULL,
>         value INT(11) NOT NULL,
>         INDEX (type, timestamp, time));
>       ");
>       break;
>     case 'pgsql':
>       db_query("CREATE TABLE feedapi_stat (
>         id int NOT NULL default '0',
>         type VARCHAR(64) NOT NULL,
>         timestamp INT NOT NULL,
>         time VARCHAR(20) NOT NULL,
>         value INT NOT NULL)
>       ");
>       db_query("CREATE INDEX type_index on feedapi_stat(type)");
>       db_query("CREATE INDEX timestamp_index on feedapi_stat(timestamp)");
>       db_query("CREATE INDEX time_index on feedapi_stat(time)");
>       db_query("CREATE INDEX id_index on feedapi_stat(id)");
>       break;
>   }
>   $result = db_query("SELECT nid, statistics FROM {feedapi}");
>   while ($stat = db_fetch_array($result)) {
>     $id = $stat["nid"];
>     $stat = unserialize($stat['statistics']);
>     $stat_fields = is_array($stat) ?  array_keys($stat) : array();
>     foreach ($stat_fields as $field) {
>       $timestamp = time();
>       $time = date("Y-m-d H:i", $timestamp);
>       foreach ($stat[$field] as $val) {
>         db_query('INSERT INTO {feedapi_stat} (id, value, time, timestamp, type) VALUES (%d, %d, "%s", %d, "%s")', $id, $val, $time, $timestamp, $field);
>       }
>     }
>   }
>   db_query("ALTER TABLE {feedapi} DROP COLUMN statistics");
>   return $ret;
> }
\ No newline at end of file
Index: feedapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feedapi/feedapi.module,v
retrieving revision 1.23.2.105
diff -r1.23.2.105 feedapi.module
113d112
<           $node->feed->statistics = unserialize($node->feed->statistics);
597a597,598
>   // Prune FeedAPI stats 4 weeks
>   db_query('DELETE FROM {feedapi_stat} WHERE timestamp < %d', variable_get('cron_semaphore', FALSE) - 28*24*3600);
627a629,631
>     foreach (array('download_num', 'new',  'process_time', 'update_times') as $type) {
>       $node->feed->statistics[$type] = _feedapi_get_stat($nid, $type, TRUE);
>     }
649,650c653,654
<   $output = format_plural(variable_get('feedapi_statistics_queue', 10), "Average over the last refresh.",
<     "Averages over the last @count refreshes."
---
>   $output = format_plural(variable_get('feedapi_statistics_lifetime', 14), "Average over the last day.",
>     "Averages over the last @count days."
734c738
<   $form['feedapi_statistics_queue'] = array(
---
>   $form['feedapi_statistics_lifetime'] = array(
736,738c740,742
<     '#title' => t('Number of samples stored per feed for statistics'),
<     '#options' => drupal_map_assoc(array(10, 20, 50, 100)),
<     '#default_value' => variable_get('feedapi_statistics_queue', 10),
---
>     '#title' => t('Statistics data lifetime in days'),
>     '#options' => drupal_map_assoc(array(1, 7, 14, 30, 365, 99999)),
>     '#default_value' => variable_get('feedapi_statistics_lifetime', 14),
1014a1019
>   $timestamp = variable_get('cron_semaphore', FALSE) !== FALSE ? variable_get('cron_semaphore', FALSE) : time();
1082a1088
>   
1084,1087c1090,1093
<     $feed->statistics['update_times'] = _feedapi_queue($feed->statistics['update_times'], time());
<     $feed->statistics['new'] = _feedapi_queue($feed->statistics['new'], $new);
<     $feed->statistics['download_num'] = _feedapi_queue($feed->statistics['download_num'], count($items));
<     $feed->statistics['process_time'] = _feedapi_queue($feed->statistics['process_time'], timer_read('feedapi_'. $feed->nid));
---
>     _feedapi_store_stat($nid, 'update_times', time(), $timestamp);
>     _feedapi_store_stat($nid, 'new', $new, $timestamp);
>     _feedapi_store_stat($nid, 'download_num', count($items), $timestamp);
>     _feedapi_store_stat($nid, 'process_time', timer_read('feedapi_'. $feed->nid), $timestamp);
1089c1095
<   db_query("UPDATE {feedapi} SET checked = %d, statistics = '%s', half_done = %d WHERE nid = %d", time(), serialize($feed->statistics), $half_done, $feed->nid);
---
>   db_query("UPDATE {feedapi} SET checked = %d, half_done = %d WHERE nid = %d", time(), $half_done, $feed->nid);
1223,1237d1228
<  * Add the element of the queue. This queue is fixed-length, the first element is discarded if full.
<  * Helper function for statistics handling
<  */
< function _feedapi_queue($queue, $new_elem) {
<   if (empty($queue) || !isset($queue)) {
<     $queue = array();
<   }
<   array_push($queue, $new_elem);
<   if (count($queue) > variable_get('feedapi_statistics_queue', 10)) {
<     array_shift($queue);
<   }
<   return $queue;
< }
< 
< /**
1322a1314,1372
>  * Store statistics information
>  *
>  * @param $id
>  *  A numerical id
>  * @param $type
>  *  A string which describes what we want to store. This is an identifier, think of as a variable name
>  * @param $val
>  *  This is the variable value
>  * @param $timestamp
>  *  Timestamp for the value
>  * @param $time
>  *  Optional, a string equivalent to the $timestamp
>  * @param $update
>  *  Boolean, TRUE if you'd like to modify an existing entry in the stat table
>  */
> function _feedapi_store_stat($id, $type, $val, $timestamp, $time = NULL, $update = FALSE) {
>   if (!$time) {
>     $time = date("Y-m-d H:i", $timestamp);
>   }
>   if ($update) {
>     $existing_val = db_result(db_query('SELECT value FROM {feedapi_stat} mn WHERE time = "%s" AND type = "%s" AND id = %d', $time, $type, $id));
>   }
>   if ($existing_val) {
>     $val = $existing_val + $val;
>     db_query('UPDATE {feedapi_stat} SET value = %d, timestamp = %d WHERE time = "%s" AND type = "%s" AND id = %d', $val, $timestamp, $time, $type, $id);
>   }
>   else {
>     db_query('INSERT INTO {feedapi_stat} (id, value, time, timestamp, type) VALUES (%d, %d, "%s", %d, "%s")', $id, $val, $time, $timestamp, $type);
>   }
> }
> 
> /**
>  * Return the type-specific statistics data
>  *
>  * @param $id
>  *  A numerical id
>  * @param $type
>  *  Name of the type (variable)
>  * @name $only_val
>  *  If TRUE, only the values are returned, no more 
>  * @return
>  *  $only_val = FALSE -> array("timestamp" => array(), "time" => array(), "value" => array());
>  */
> function _feedapi_get_stat($id, $type, $only_val = FALSE) {
>   $result = db_query("SELECT timestamp, time, value FROM {feedapi_stat} WHERE type = '%s' AND id = %s", $type, $id);
>   while ($row = db_fetch_array($result)) {
>     if ($only_val) {
>       $stat[] = $row['value'];
>     }
>     else {
>       foreach (array('timestamp', 'time', 'value') as $member) {
>         $stat[$member][] = $row[$member];
>       }
>     }
>   }
>   return $stat;
> }
> 
> /**
