I had a view with 4 filters and 500+ nodes (products), and it takes 10-15 seconds for the view to generate every time. The easiest solution was to use caching, so here is my alterations to the views_handler_filter_selective.inc file to speed things up greatly ( < 1 second render).

  function get_oids() {
    $exposed_input = isset($this->view->exposed_input) ? $this->view->exposed_input : array();
    $signature = md5(serialize(array(
      'name' => $this->view->name,
      'args' => $this->view->args,
      'input' => $exposed_input,
    )));
    if (empty(self::$results[$signature])) {
      // first lets see if it exists in the cache
      $cache = cache_get($signature, 'cache_filter');
      if (!empty($cache)){
                self::$results[$signature]=$cache->data;
          }
    }
    if (empty(self::$results[$signature])) {
      // Clone the view and get all results.
      $view_copy = views_get_view($this->view->name);
      if (!$view_copy) return NULL;
      $view_copy->selective_oids = TRUE;
      $view_copy->set_exposed_input($exposed_input);
      $view_copy->set_arguments($this->view->args);
      $view_copy->set_items_per_page(0);
      if (isset($_GET['items_per_page'])) {
        $items_per_page = $_GET['items_per_page'];
        unset($_GET['items_per_page']);
      }
      $view_copy->execute($this->view->current_display);
      if (isset($items_per_page)) {
        $_GET['items_per_page'] = $items_per_page;
      }
      $oids = array();
      foreach ($view_copy->result as $row) {
        $oids[] = $row->{$view_copy->base_field};
      }
      if (empty($this->view->base_field)) {
        $this->view->base_field = $view_copy->base_field;
      }
      self::$results[$signature] = $oids;
      cache_set($signature, $oids, 'cache_filter', time() + 60*60);
      $view_copy->destroy();
    }
    return self::$results[$signature];
  }

Comments

mellowtothemax’s picture

I am also having this problem. My number of nodes exceed 10,000 and as a result there is high cpu usage whenever the view is generated and can take up to 30 seconds. This is a big problem for my site and server. The above solution did help for me and neither does caching the view itself.

I can confirm that without the selective filters, the pages load instantly. Using the standard views filters also doesn't cause a problem. I have noticed that the pager seems to be ignored in the initial query when the page loads.

Any help would be appreciated.

infojunkie’s picture

Status: Active » Closed (won't fix)

This module has been deprecated in favour of https://drupal.org/project/views_selective_filters. Please test there and reopen if necessary.