summaryrefslogtreecommitdiff
path: root/modules/statistics
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-05-18 18:26:30 +0000
committerDries Buytaert <dries@buytaert.net>2010-05-18 18:26:30 +0000
commit09b0283675f938c89a2c541b6649deb10e7c5040 (patch)
treeb057e0dd997cbe6ab096c3651593768fbb76dcf4 /modules/statistics
parentd4200e260003dc1e75cd27db8f1b286fa6a30931 (diff)
downloadbrdo-09b0283675f938c89a2c541b6649deb10e7c5040.tar.gz
brdo-09b0283675f938c89a2c541b6649deb10e7c5040.tar.bz2
- Patch #692044 by Damien Tournoud, effulgentsia: a site with statistics module enabled is much slower in serving cached pages in D7 than in D6.
Diffstat (limited to 'modules/statistics')
-rw-r--r--modules/statistics/statistics.module8
-rw-r--r--modules/statistics/statistics.test63
2 files changed, 70 insertions, 1 deletions
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index fce5f6acf..983dba45b 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -51,7 +51,12 @@ function statistics_help($path, $arg) {
function statistics_exit() {
global $user;
- drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ // When serving cached pages with the 'page_cache_without_database'
+ // configuration, system variables need to be loaded. This is a major
+ // performance decrease for non-database page caches, but with Statistics
+ // module, it is likely to also have 'statistics_enable_access_log' enabled,
+ // in which case we need to bootstrap to the session phase anyway.
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
if (variable_get('statistics_count_content_views', 0)) {
// We are counting content views.
@@ -70,6 +75,7 @@ function statistics_exit() {
}
}
if (variable_get('statistics_enable_access_log', 0)) {
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
// Log this page access.
db_insert('accesslog')
->fields(array(
diff --git a/modules/statistics/statistics.test b/modules/statistics/statistics.test
index 283c2d9da..8922144ad 100644
--- a/modules/statistics/statistics.test
+++ b/modules/statistics/statistics.test
@@ -34,6 +34,69 @@ class StatisticsTestCase extends DrupalWebTestCase {
}
/**
+ * Tests that logging via statistics_exit() works for cached and uncached pages.
+ *
+ * Subclass DrupalWebTestCase rather than StatisticsTestCase, because we want
+ * to test requests from an anonymous user.
+ */
+class StatisticsLoggingTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Statistics logging tests',
+ 'description' => 'Tests request logging for cached and uncached pages.',
+ 'group' => 'Statistics'
+ );
+ }
+
+ function setUp() {
+ parent::setUp('statistics');
+
+ // Ensure we have a node page to access.
+ $this->node = $this->drupalCreateNode();
+
+ // Enable page caching.
+ variable_set('cache', TRUE);
+
+ // Enable access logging.
+ variable_set('statistics_enable_access_log', 1);
+ variable_set('statistics_count_content_views', 1);
+
+ // Clear the logs.
+ db_truncate('accesslog');
+ db_truncate('node_counter');
+ }
+
+ /**
+ * Verifies request logging for cached and uncached pages.
+ */
+ function testLogging() {
+ $path = 'node/' . $this->node->nid;
+ $expected = array(
+ 'title' => $this->node->title,
+ 'path' => $path,
+ );
+
+ // Verify logging of an uncached page.
+ $this->drupalGet($path);
+ $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Testing an uncached page.'));
+ $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
+ $this->assertTrue(is_array($log) && count($log) == 1, t('Page request was logged.'));
+ $this->assertEqual(array_intersect_key($log[0], $expected), $expected);
+ $node_counter = statistics_get($this->node->nid);
+ $this->assertIdentical($node_counter['totalcount'], '1');
+
+ // Verify logging of a cached page.
+ $this->drupalGet($path);
+ $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Testing a cached page.'));
+ $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
+ $this->assertTrue(is_array($log) && count($log) == 2, t('Page request was logged.'));
+ $this->assertEqual(array_intersect_key($log[1], $expected), $expected);
+ $node_counter = statistics_get($this->node->nid);
+ $this->assertIdentical($node_counter['totalcount'], '2');
+ }
+}
+
+/**
* Tests that report pages render properly, and that access logging works.
*/
class StatisticsReportsTestCase extends StatisticsTestCase {