Index: modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.272 diff -u -r1.272 statistics.module --- modules/statistics/statistics.module 4 Jan 2008 09:31:48 -0000 1.272 +++ modules/statistics/statistics.module 5 Feb 2008 00:59:55 -0000 @@ -50,12 +50,23 @@ 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. - db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1)); - // If we affected 0 rows, this is the first time viewing the node. - if (!db_affected_rows()) { - // We must create a new row to store counters for the new node. - db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time()); + switch (variable_get('statistics_enable_access_log', 0)) { + // With enabled access log, we can determine whether this is a unique + // page view or not. We are checking this by Session ID. + case TRUE: + $result = db_query("SELECT title FROM {accesslog} WHERE path = '%s' AND sid = '%s' AND uid = %d", $_GET['q'], session_id(), $user->uid); + // Break, if this page has been already viewed in this session. + if (db_num_rows($result)) { + break; + } + // In all other cases increment the counter by one. + default: + db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1)); + // If we didn't affect any row, this node has not yet been viewed by + // any user. Therefore we need to create a new row for this node. + if (!db_affected_rows()) { + db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time()); + } } } }