Template Node Variables getting hung up on large datasets

R.J._Steinert - September 19, 2008 - 21:06
Project:Active Template
Version:5.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

We have a case where a View returns a result set of over 15,000. When results get this large a server will often get hung up on line 1268 of active_view.module.

<?php
 
foreach ($nodes as $node) {
   
$rendered_nodes[] = template_api_prepare_node($node->nid, $teaser, TRUE); 
  }
?>

I understand that this has to be done due to the fact that setting views_build_view()'s $type parameter to 'items' on line 658 does not return the each node's type field. Yet, even if it did return the node's type field, then there would still be a lot of processing to sort out distinct node types using PHP.

My quick fix is to change the views_build_views()'s type parameter to 'query' and add 'GROUP BY node.type' to the SQL statement. In the case of a View result set of 15,000, this reduces the amount of queries from over 15,000 to under 10. There is some other logic to clean up (the 'Node count:' field on the form is confused, it's actually displaying the number of node types at this point) but it serves the purpose.

<?php
  $views_queries
= views_build_view('queries', $view);
 
$query = $views_queries['query'];
 
$str_pos = strripos($query, ")");
 
$query = substr($query, 0, $str_pos+1);
 
$query .= ' GROUP BY node.type';
 
$result = db_query($query);
  while(
$node = db_fetch_object($result)){
     
$nodes[] = $node;
  }
  return
active_view_prepare_nodes($view, $nodes, $template->type); 
?>

I would be willing to commit this and clean up the surrounding logic.

 
 

Drupal is a registered trademark of Dries Buytaert.