summaryrefslogtreecommitdiff
path: root/modules
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
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')
-rw-r--r--modules/statistics/statistics.module8
-rw-r--r--modules/statistics/statistics.test63
-rw-r--r--modules/system/system.install15
-rw-r--r--modules/update/update.install7
-rw-r--r--modules/update/update.module4
5 files changed, 87 insertions, 10 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 {
diff --git a/modules/system/system.install b/modules/system/system.install
index 5f01d45b8..a80e6ceda 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -634,11 +634,6 @@ function system_schema() {
'not null' => TRUE,
'default' => 0,
),
- 'headers' => array(
- 'description' => 'Any custom HTTP headers to be added to cached data.',
- 'type' => 'text',
- 'not null' => FALSE,
- ),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
@@ -2382,6 +2377,16 @@ function system_update_7053() {
}
/**
+ * Remove {cache_*}.headers columns.
+ */
+function system_update_7054() {
+ $cache_tables = array('cache', 'cache_bootstrap', 'cache_filter', 'cache_form', 'cache_menu', 'cache_page', 'cache_path');
+ foreach ($cache_tables as $table) {
+ db_drop_field($table, 'headers');
+ }
+}
+
+/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
*/
diff --git a/modules/update/update.install b/modules/update/update.install
index 00935f190..f324ce570 100644
--- a/modules/update/update.install
+++ b/modules/update/update.install
@@ -167,3 +167,10 @@ function update_update_7000() {
$queue = DrupalQueue::get('update_fetch_tasks');
$queue->createQueue();
}
+
+/**
+ * Remove {cache_update}.headers columns.
+ */
+function update_update_7001() {
+ db_drop_field('cache_update', 'headers');
+}
diff --git a/modules/update/update.module b/modules/update/update.module
index 02bdabaef..1704fdfff 100644
--- a/modules/update/update.module
+++ b/modules/update/update.module
@@ -653,9 +653,6 @@ function theme_update_last_check($variables) {
/**
* Store data in the private update status cache table.
*
- * Note: this function completely ignores the {cache_update}.headers field
- * since that is meaningless for the kinds of data we're caching.
- *
* @param $cid
* The cache ID to save the data with.
* @param $data
@@ -671,7 +668,6 @@ function _update_cache_set($cid, $data, $expire) {
$fields = array(
'created' => REQUEST_TIME,
'expire' => $expire,
- 'headers' => NULL,
);
if (!is_string($data)) {
$fields['data'] = serialize($data);