Jump to content


Uncached snippets not evaluating-resolution


  • You cannot reply to this topic
1 reply to this topic

#1 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 21 February 2009 - 01:57 AM

I'm pretty sure that this solves the problem of uncached snippets not evaluating... This is the beginning of the ouputContent() function from the etomite V1.1 index.php approx line 281:

function outputContent() {
 $output = $this->documentContent;
 
 $this->nonCachedSnippetParsePasses = empty($this->nonCachedSnippetParsePasses) ? 1 : $this->nonCachedSnippetParsePasses;
 for($i=0; $i<$this->nonCachedSnippetParsePasses; $i++) {
 
//moved inside this loop
 if(strpos($output, '[!')>-1) {
 $output = str_replace('[!', '[[', $output);
 $output = str_replace('!]', ']]', $output);
 }
 if($this->config['dumpSnippets']==1) {
 echo "<fieldset style='text-align: left'><legend>NONCACHED PARSE PASS ".($i+1)."</legend>The following snippets (if any) were parsed during this pass.<div style='width:100%' align='center'>";
 }
 // replace settings referenced in document
 $output = $this->mergeSettingsContent($output);
 // replace HTMLSnippets in document
 $output = $this->mergeHTMLSnippetsContent($output);
 // find and merge snippets
 $output = $this->evalSnippets($output);
 if($this->config['dumpSnippets']==1) {
 echo "</div></fieldset><br />";
 }
 }

My rationale for this change:

I narrowed it down by nesting snippets and pages with snippets (both cached and uncached pages and snippets) until I realised what was not evaluating and under what circumstances. I realised that only uncached snippets in uncached pages (or snippets) nested 2 levels deep are not evaluated. Then I looked at how the cache is built and realised that all the [!uncached!]snippets should be changed to [[cached]] so that the evalSnippets() can find them. It is here that the number of recognised snippets are compared to the cache (at this stage, the uncached snippets are incorrectly not being counted) and if they are NOT found in the cache, direct database calls to evaluate the snippets are performed.

So I had a look at the replace mechanism and in the original outputContent(), the str_replace('[!','[[',$output); happened before the nonCachedSnippetParsePasses() loop.

Therefore, uncached snippets were not being evaluated by the evalSnippets() later in the loop because they were not being read, ie still [!uncached!] (remember, the evalSnippets() is ONLY looking for [[cached]] snippet tags at this stage.

The resolution was to move the str_replace INSIDE the nonCachedSnippetParsePasses() loop so that for each parse, the uncached snippets are migrated to [[cached]] so they can stand up and be counted in the evalSnippets() later in the loop.

This makes the RSS snippets, getDcContent, getSidebar and other nested snippets work like a rocket!

Also this fixes the nested runSnippet() issue where only the first level runSnippet() evaluates. I tested if to 5 levels deep, and all snippets evaluated in the first non-cached parse. ie
Message snippet:
return "successfully evaluated";
Snippet1:
return $etomite->runSnippet('message');
Snippet2:
return $etomite->runSnippet('snippet1');
Snippet3:
return $etomite->runSnippet('snippet2');
Snippet4:
return $etomite->runSnippet('snippet3');
Snippet5:
return $etomite->runSnippet('snippet4');

In the content, [!snippet5!] evaluates to "successfully evaluated"!

[edit] this also fixes problems where there are snippets in snippets in pages, like when getSideBar contains authenticate_visitor and occasions where lots of the page is generated dynamically.


Problem solved.

Edited by Cris D., 19 September 2009 - 09:14 PM.


#2 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 21 February 2009 - 03:07 PM

Thanks, Cris... I'll check this patch out and also make sure I haven't already addressed the issue in the v1.2 code base... I don't recall whether I made any changes but I do recall investigating the problem shortly after v1.1 was released...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users