Skip to content
Snippets Groups Projects
Commit 87986e31 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2404039 by Lendude, jhedstrom, fgm, zealfire, adci_contributor,...

Issue #2404039 by Lendude, jhedstrom, fgm, zealfire, adci_contributor, dawehner: Views performance statistics do not properly display
parent af581611
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -90,6 +90,34 @@ function testPreviewUI() { ...@@ -90,6 +90,34 @@ function testPreviewUI() {
$this->drupalPostForm(NULL, array(), t('Update preview')); $this->drupalPostForm(NULL, array(), t('Update preview'));
$result = $this->xpath('//div[@id="views-live-preview"]/pre'); $result = $this->xpath('//div[@id="views-live-preview"]/pre');
$this->assertTrue(strpos($result[0], '<title>' . $view['page[title]'] . '</title>'), 'The Feed RSS preview was rendered.'); $this->assertTrue(strpos($result[0], '<title>' . $view['page[title]'] . '</title>'), 'The Feed RSS preview was rendered.');
// Test the non-default UI display options.
// Statistics only, no query.
$settings = \Drupal::configFactory()->getEditable('views.settings');
$settings->set('ui.show.performance_statistics', TRUE)->save();
$this->drupalGet('admin/structure/views/view/test_preview/edit');
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
$this->assertText(t('Query build time'));
$this->assertText(t('Query execute time'));
$this->assertText(t('View render time'));
$this->assertNoRaw('<strong>Query</strong>');
// Statistics and query.
$settings->set('ui.show.sql_query.enabled', TRUE)->save();
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
$this->assertText(t('Query build time'));
$this->assertText(t('Query execute time'));
$this->assertText(t('View render time'));
$this->assertRaw('<strong>Query</strong>');
$this->assertText("SELECT views_test_data.name AS views_test_data_name\nFROM \n{views_test_data} views_test_data\nWHERE (( (views_test_data.id = &#039;100&#039; ) ))");
// Test that the statistics and query are rendered above the preview.
$this->assertTrue(strpos($this->getRawContent(), 'views-query-info') < strpos($this->getRawContent(), 'view-test-preview') , 'Statistics shown above the preview.');
// Test that statistics and query rendered below the preview.
$settings->set('ui.show.sql_query.where', 'below')->save();
$this->drupalPostForm(NULL, $edit = array('view_args' => '100'), t('Update preview'));
$this->assertTrue(strpos($this->getRawContent(), 'view-test-preview') < strpos($this->getRawContent(), 'views-query-info'), 'Statistics shown below the preview.');
} }
/** /**
......
...@@ -45,26 +45,12 @@ class ViewUI implements ViewEntityInterface { ...@@ -45,26 +45,12 @@ class ViewUI implements ViewEntityInterface {
public $changed_display; public $changed_display;
/** /**
* How long the view takes to build. * How long the view takes to render in microseconds.
* *
* @var int * @var float
*/
public $build_time;
/**
* How long the view takes to render.
*
* @var int
*/ */
public $render_time; public $render_time;
/**
* How long the view takes to execute.
*
* @var int
*/
public $execute_time;
/** /**
* If this view is locked for editing. * If this view is locked for editing.
* *
...@@ -636,12 +622,15 @@ public function renderPreview($display_id, $args = array()) { ...@@ -636,12 +622,15 @@ public function renderPreview($display_id, $args = array()) {
$this->endQueryCapture(); $this->endQueryCapture();
} }
$this->render_time = Timer::stop('entity.view.preview_form'); $this->render_time = Timer::stop('entity.view.preview_form')['time'];
views_ui_contextual_links_suppress_pop(); views_ui_contextual_links_suppress_pop();
// Prepare the query information and statistics to show either above or // Prepare the query information and statistics to show either above or
// below the view preview. // below the view preview.
// Initialise the empty rows arrays so we can safely merge them later.
$rows['query'] = [];
$rows['statistics'] = [];
if ($show_info || $show_query || $show_stats) { if ($show_info || $show_query || $show_stats) {
// Get information from the preview for display. // Get information from the preview for display.
if (!empty($executable->build_info['query'])) { if (!empty($executable->build_info['query'])) {
...@@ -769,7 +758,7 @@ public function renderPreview($display_id, $args = array()) { ...@@ -769,7 +758,7 @@ public function renderPreview($display_id, $args = array()) {
'#template' => "<strong>{% trans 'View render time' %}</strong>", '#template' => "<strong>{% trans 'View render time' %}</strong>",
), ),
), ),
t('@time ms', array('@time' => intval($executable->render_time * 100000) / 100)), t('@time ms', array('@time' => intval($this->render_time * 100) / 100)),
); );
} }
\Drupal::moduleHandler()->alter('views_preview_info', $rows, $executable); \Drupal::moduleHandler()->alter('views_preview_info', $rows, $executable);
...@@ -827,26 +816,16 @@ public function renderPreview($display_id, $args = array()) { ...@@ -827,26 +816,16 @@ public function renderPreview($display_id, $args = array()) {
'#type' => 'table', '#type' => 'table',
'#prefix' => '<div class="views-query-info">', '#prefix' => '<div class="views-query-info">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#rows' => array_merge($rows['query'], $rows['statistics']),
); );
if ($show_location === 'above' || $show_location === 'below') {
if ($combined) {
$table['#rows'] = array_merge($rows['query'], $rows['statistics']);
}
else {
$table['#rows'] = $rows['query'];
}
}
elseif ($show_stats === 'above' || $show_stats === 'below') {
$table['#rows'] = $rows['statistics'];
}
if ($show_location === 'above' || $show_stats === 'above') { if ($show_location == 'above') {
$output = [ $output = [
'table' => $table, 'table' => $table,
'preview' => $preview, 'preview' => $preview,
]; ];
} }
elseif ($show_location === 'below' || $show_stats === 'below') { else {
$output = [ $output = [
'preview' => $preview, 'preview' => $preview,
'table' => $table, 'table' => $table,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment