Index: modules/statistics/statistics.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.install,v
retrieving revision 1.13
diff -u -p -r1.13 statistics.install
--- modules/statistics/statistics.install	18 Dec 2007 12:59:22 -0000	1.13
+++ modules/statistics/statistics.install	2 Sep 2008 05:38:23 -0000
@@ -112,6 +112,7 @@ function statistics_schema() {
     'indexes' => array(
       'accesslog_timestamp' => array('timestamp'),
       'uid' => array('uid'),
+      'accesslog_path_sid' => array('path', 'sid'),
     ),
     'primary key' => array('aid'),
   );
@@ -119,3 +120,11 @@ function statistics_schema() {
   return $schema;
 }
 
+/**
+ * Adds index for repeat content view checking.
+ */
+function statistics_update_7000() {
+  $ret = array();
+  db_add_index($ret, 'accesslog', 'accesslog_path_sid', array('path', 'sid'));
+  return $ret;
+}
Index: modules/statistics/statistics.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v
retrieving revision 1.280
diff -u -p -r1.280 statistics.module
--- modules/statistics/statistics.module	21 Aug 2008 19:36:38 -0000	1.280
+++ modules/statistics/statistics.module	2 Sep 2008 05:38:31 -0000
@@ -50,30 +50,37 @@ function statistics_exit() {
   if (variable_get('statistics_count_content_views', 0)) {
     // We are counting content views.
     if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
-      // A node has been viewed, so update the node's counters.
-      $fields = array(
-        'daycount' => 1,
-        'totalcount' => 1,
-        'nid' => arg(1),
-        'timestamp' => time(),
-      );
-      db_merge('node_counter')
-        ->fields($fields)
-        ->expression('daycount', 'daycount + 1')
-        ->expression('totalcount', 'totalcount + 1')
-        ->execute();
+      // With enabled access log, we can determine whether this is a unique
+      // page view or not. We are checking this by using the history table and
+      // checking for the same Session ID and path in the accesslog table.
+      $viewed = $user->uid && db_result(db_query("SELECT 1 FROM {history} WHERE nid = %d AND uid = %d", arg(1), $user->uid));
+      $viewed = !$viewed || variable_get('statistics_enable_access_log', 0) && db_result(db_query_range("SELECT 1 FROM {accesslog} WHERE path = '%s' AND sid = '%s'", array($_GET['q'], session_id()), 0, 1));
+      if (!$viewed) {
+        // A node has been viewed, so update the node's counters.
+        $fields = array(
+          'daycount' => 1,
+          'totalcount' => 1,
+          'nid' => arg(1),
+          'timestamp' => time(),
+        );
+        db_merge('node_counter')
+          ->fields($fields)
+          ->expression('daycount', 'daycount + 1')
+          ->expression('totalcount', 'totalcount + 1')
+          ->execute();
+      }
     }
   }
   if (variable_get('statistics_enable_access_log', 0)) {
     // Log this page access.
     db_insert('accesslog')->fields(array(
       'title' => strip_tags(drupal_get_title()),
-      'path' => $_GET['q'], 
-      'url' => referer_uri(), 
-      'hostname' => ip_address(), 
-      'uid' => $user->uid, 
-      'sid' => session_id(), 
-      'timer' => timer_read('page'), 
+      'path' => $_GET['q'],
+      'url' => referer_uri(),
+      'hostname' => ip_address(),
+      'uid' => $user->uid,
+      'sid' => session_id(),
+      'timer' => timer_read('page'),
       'timestamp' => time(),
     ))->execute();
   }
