Skip to main content.

Saturday, June 12, 2004

Update 2004-06-13: The commit from yesterday contained an error which caused nested ifs not to work correctly. Now fixed.

Today, I committed a small improvement to the PARSER.php class into CVS. It greatly improves performance on sites with complex if-else structures.

Here's what happened in the past when an <%if> was encountered:The condition was evaluated and added to a stack, after which output buffering was started. When an else / endif skinvar was encountered, the buffer was either dumped to the output (if the condition was true), or discarded (if the condition was false).

The problem with this approach is that skinvars in an undisplayed if section are still executed. Consider the following example:

<%if(...)%>
  <%blog(template1,15)%>
<%endif%>
<%if(...)%>
  <%blog(template2,15)%>
<%endif%>
<%if(...)%>
  <%blog(template3,15)%>
<%endif%>

In this case, each of the blog skinvars would cause the database to be queried for blog items and templates, and the templates would be applied to those blog items.

The solution is rather simple:

  • At each time, have a variable telling if the data will be seen by the client or not: either 1 or 0 is stored in the if_currentlevel variable, defined and managed in the BaseActions class.
  • While parsing, ignore all actions except if, else and endif when if_currentlevel is 0

The data in between skinvars is still sent to the buffered output, which is discarded afterwards. But I don't think this is a big problem.

Comments

No comments yet

Add Comment

This item is closed, it's not possible to add new comments to it or to vote on it