Commit 93478024 authored by Roger Codina's avatar Roger Codina Committed by Liam Morland
Browse files

Issue #2628014: Fix performance and memory regression in pager fix

Fixes problem caused by 2cd1ba8e.
parent ef9c2828
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class views_php_handler_field extends views_handler_field {
      array('$view', '$handler', '$static', '$row', '$data')
    );
    $form += views_php_form_element($this,
      array('use_php_click_sortable', t('Enable click sort'), t('If checked, you can use PHP code to enable click sort on the field.')),
      array('use_php_click_sortable', t('Enable click sort'), t('If checked, you can use PHP code to enable click sort on the field. This may have a large performance impact as all results will be loaded from the database, and pager limits will only be applied in PHP.')),
      array('php_click_sortable', t('Click sort code'), t('The comparison code must return an integer less than, equal to, or greater than zero if the first row should respectively appear before, stay where it was compared to, or appear after the second row.'), FALSE),
      array(
        '$view', '$handler', '$static',
@@ -88,6 +88,9 @@ class views_php_handler_field extends views_handler_field {
    $this->field_alias = 'views_php_' . $this->position;
    // Inform views_php_views_pre_execute() to seize control over the query.
    $this->view->views_php = TRUE;
    if ($this->click_sortable()) {
      $this->view->views_php_query_all = TRUE;
    }
  }

  /**
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ class views_php_handler_filter extends views_handler_filter {
  public function query() {
    // Inform views_php_views_pre_execute() to seize control over the query.
    $this->view->views_php = TRUE;
    $this->view->views_php_query_all = TRUE;
  }

  /**
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ class views_php_handler_sort extends views_handler_sort {
  public function query() {
    // Inform views_php_views_pre_execute() to seize control over the query.
    $this->view->views_php = TRUE;
    $this->view->views_php_query_all = TRUE;
  }

  /**
+13 −9
Original line number Diff line number Diff line
@@ -21,9 +21,11 @@ class views_php_plugin_pager extends views_php_plugin_wrapper {
      }
    }

    if (!empty($this->wrapped->view->views_php_query_all)) {
      $this->wrapped->view->query->set_limit(0);
      $this->wrapped->view->query->set_offset(0);
    }
  }

  /**
   * Perform any needed actions just after the query executing.
@@ -37,6 +39,7 @@ class views_php_plugin_pager extends views_php_plugin_wrapper {
      }
    }

    if (!empty($this->wrapped->view->views_php_query_all)) {
      $this->wrapped->total_items = count($this->wrapped->view->result);
      $this->wrapped->update_page_info();

@@ -47,6 +50,7 @@ class views_php_plugin_pager extends views_php_plugin_wrapper {
      }
      $this->wrapped->post_execute($result);
    }
  }

  /**
   * Execute the count query, which will be done just prior to the query
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ function views_php_views_post_execute($view) {
 */
function views_php_views_post_build($view) {
  // Clear the limit and offset.
  if (!empty($view->views_php) && !empty($view->build_info['query']) && is_object($view->build_info['query'])) {
  if (!empty($view->views_php) && !empty($view->views_php_query_all) && !empty($view->build_info['query']) && is_object($view->build_info['query'])) {
    $view->build_info['query']->range();
  }
}